Browser/LibModuleSymbol.pm untested

filter: Statementstmt 0.0% 0 / 99 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 155 CC 17 SCAR 33.1
CC
17
Cov
0%
xrefs
56.0
text_symbols
42.0
scannedpackages
6.0
CRAP 27.3
1 package Browser::LibModuleSymbol;
2 my $RCSRevKey = '$Revision: 1.1.1.1 $';
3 $RCSRevKey =~ /Revision: (.*?) /;
4 $VERSION=0.53;
5 use vars qw( @ISA @EXPORT @EXPORT_OK $VERSION );
6 push @ISA, qw( Exporter DB );
7  
8 =head1 NAME
9  
10 Browser::LibModuleSymbol.pm -- Scanning of Perl symbol tables and
11 library modules.
12  
13 =head1 DESCRIPTION
14  
15 Browser::LibModuleSymbol.pm Provides Perl symbol table and lexical
16 routines for Tk::Browser(3).
17  
18 =head1 REVISION
19  
20 $Id: LibModuleSymbol.pm,v 1.1.1.1 2015/04/18 18:43:42 rkiesling Exp $
21  
22 =head1 SEE ALSO
23  
24 Browser::LibModule(3), Tk::Browser(3), perlmod(1), perlmodlib(1), perl(1).
25  
26 =cut
27  
28 sub new {
29 my $proto = shift;
30 my $class = ref( $proto ) || $proto;
31 my $self = {
32 pathname => undef,
33 packagename => undef,
34 version => undef,
35 refsymbols => []
36 };
37 bless( $self, $class);
38 return $self;
39  
40 }
41  
42 my @scannedpackages;
43  
44 sub scannedpackages {
45 if( @_ ) { @scannedpackages = @_ }
46 return @scannedpackages;
47 }
48  
49 sub text_symbols {
50 my $p = shift;
51 my (@text, $pathname) = @_;
52 my @matches;
53 my $nmatches;
54 my $package;
55 my @unsortedsymbols;
56 my ($i, $j, $k);
57 if ($text[0] =~ /^package/) { $package = $text[0] };
58 if ($package) {
59 $package =~ s/(^package\s+)|(\s*\;.*$)//g;
60 chop $package;
61 } else {
62 return undef;
63 }
64 @matches = grep /$package/, @scannedpackages;
65 return undef if ( $nmatches = @matches );
66 @matches = grep /\$VERSION/, @text;
67 $matches[0] =~ /(\$VERSION[ \t]*=[ \t]*(.*?)\;)/ if $matches[0];
68 my $ver = $2;
69 $p -> {pathname} = $pathname;
70 $p -> {packagename} = $package;
71 $p -> {version} = $ver;
72 # find subs;
73 @{$p -> {refsymbols}} = grep /^sub\s+\S*?.*$/, @text;
74 # find everything else
75 @matches = grep /[\$\@\%]\w+/, @text;
76 VARS: foreach $i ( @matches ) {
77 $i =~ /([\$\@\%]\w+)/;
78 $j = $1;
79 foreach $k ( @{$p -> {refsymbols}} ) {
80 next VARS if $k eq $j;
81 }
82 push @{$p -> {refsymbols}}, ($j);
83 }
84 push @scannedpackages, ($package);
85 return 1;
86 }
87  
88 my %xrefcache;
89  
90 sub xrefcache {
91 my $self = shift;
92 if (@_) { $self -> {xrefcache} = shift; }
93 return $self -> {xrefcache}
94 }
95  
96 sub xrefs {
97 my $symobject = shift;
98 my ($sym) = @_;
99 my $key;
100 my $modulepathname;
101 my @packagefiles = ();
102 my @text;
103 my @matches;
104 my $nmatches;
105 my $i = 0;
106 foreach $key ( keys %{*{"main\:\:"}} ) {
107 if( $key =~ /^\_\<(.*)$/ ) {
108 $modulepathname = $1;
109 next if $modulepathname !~ /\.pm$/;
110 if( $xrefcache{$modulepathname} ) {
111 push @text, @{$xrefcache{$modulepathname}};
112 } elsif( open MODULE, "<$modulepathname" ) {
113 @text = <MODULE>;
114 # weed out comments
115 foreach (@text) { $_ =~ s/\#.*$// }
116 close MODULE;
117 push @{$xrefcache{$modulepathname}}, @text;
118 }
119 if ( &usesTk ) {
120 &Tk::Event::DoOneEvent(255);
121 }
122 @matches = grep /$sym/, @text;
123 $nmatches = @matches;
124 # print "$sym: $nmatches match(es): in $modulepathname:\n";
125 # foreach (@matches ) {print " $_\n";}
126 push @packagefiles, ($modulepathname) if ($nmatches > 0) ;
127 }
128 }
129 return @packagefiles;
130 }
131  
132 sub pathname {
133 my $self = shift;
134 if (@_) { $self -> {pathname} = shift; }
135 return $self -> {pathname}
136 }
137  
138 sub packagename {
139 my $self = shift;
140 if (@_) { $self -> {packagename} = shift; }
141 return $self -> {packagename}
142 }
143  
144 sub refsymbols {
145 my $self = shift;
146 if (@_) { $self -> {refsymbols} = shift; }
147 return $self -> {refsymbols}
148 }
149  
150 sub usesTk {
151 return ( exists ${"main\:\:"}{"Tk\:\:"} );
152 }
153  
154 1;
155