Extracting Information with ox.pl

The ox.pl program is the companion to oxgen.pl. It generates reports based on the information gathered by oxgen.pl.

The program itself is simple. First you grab the data stored by oxgen.pl:

35 my $object_xref = retrieve("object_xref.dat");

Then you print the entry for each symbol entered on the command line:

45      my $info = $object_xref–>{$sym}; 
46      if (not defined($info)) {
47          print "$sym:   UNDEFINED
"; 
48          next; 
49      } 
50      # Print the information 
51      print "$sym
"; 
52      print "    Defined: @{$info–>{'defined'}}
"; 
53      print "    Used: @{$info–>{'used'}}
";

That’s it—database retrieval and report generation in one easy lesson. The program is shown in its entirety in Listing 16.10.

Listing 16.10. ox.pl
 1 =pod 
 2 
 3 =head1 NAME 
 4 
 5 ox.pl – Print out object cross reference information 
 6 
 7 =head1 SYNOPSIS 
 8 
 9     ox.pl <symbol> [<symbol> ...] 
10 
11 =head1 DESCRIPTION 
12 
13 The I<ox.pl> prints out where a symbol is defined and used. 
14 
15 =head1 FILES 
16 
17 =over 4 
18 
19 =item object_xref.dat 
20 
21 The database containing the symbol information. 
22 
23 =back 
24 
25 =head1 SEE ALSO 
26 
27 L<ox–gen.pl>, L<nm> 
28 
29 =cut 
30 use strict; 
31 use warnings; 
32 use Storable; 
33 
34 # The cross reference data 
35 my $object_xref = retrieve("object_xref.dat"); 
36 
37 if (not defined($object_xref)) {
38     print "Could not find data file
"; 
39     exit (8); 
40 } 
41 
42 # Look through each symbol on the command line 
43 foreach my $sym (@ARGV) {
44      # Get the information about this symbol 
45      my $info = $object_xref–>{$sym}; 
46      if (not defined($info)) {
47          print "$sym:   UNDEFINED
"; 
48          next; 
49      } 
50      # Print the information 
51      print "$sym
"; 
52      print "    Defined: @{$info–>{'defined'}}
"; 
53      print "    Used: @{$info–>{'used'}}
"; 
54 }

Additional Work

You can use the object cross-reference database in other ways also. For example, you could use it to check to see what symbols are defined but never used. Or you could count the dependencies between modules.

The point is that you have the data stored in a way that can be conveniently accessed. What you do with it is up to you.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset