| 1 | package LEOCHARRE::PMSubs; | ||||||||||||||||||||||||||||||
| 2 | 1 | require Exporter; | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use vars qw(@ISA $VERSION @EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||
| 8 | 1 | @EXPORT_OK =qw(subs_defined _subs_defined _subs_used subs_used); | |||||||||||||||||||||||||||||
| 9 | 1 | %EXPORT_TAGS = ( all => \@EXPORT_OK ); | |||||||||||||||||||||||||||||
| 10 | 1 | $VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)/g; | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use LEOCHARRE::DEBUG; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | sub subs_defined { | ||||||||||||||||||||||||||||
|
Subroutine
subs_defined: called CC=5 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 14 | 2 | my ($abs_file,$public_only) = @_; | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | defined $abs_file or confess('missing file arg'); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | $public_only ||=0; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$public_only ||= 0
MC/DC0%0/1
$public_only ||= 0
$public_only
Truth table50%1/2
A
A= $public_only
| |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | -f $abs_file or warn("File [$abs_file] is not a file.") and return []; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
-f $abs_file || warn("File [$abs_file] is not a file.") && (return [])
warn "File [$abs_file] is not a file." and return []
MC/DC0%0/2
-f $abs_file || warn("File [$abs_file] is not a file.") && (return [])
-f $abs_file
warn "File [$abs_file] is not a file."
Truth table33%1/3
A || B
A= -f $abs_fileB= warn "File [$abs_file] is not a file."
| |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | 2 | my $code = _slurp($abs_file); | |||||||||||||||||||||||||||||
| 21 | 2 | my $subs = _subs_defined($code,$public_only); | |||||||||||||||||||||||||||||
| 22 | 2 | return $subs; | |||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | sub _subs_defined { | ||||||||||||||||||||||||||||
|
Subroutine
_subs_defined: called CC=9 SCAR=23.8
| |||||||||||||||||||||||||||||||
| 27 | 3 | my ($code,$public_only) = @_; | |||||||||||||||||||||||||||||
| 28 | 3 | ▶ | defined $code or carp('missing code arg ') and return []; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
defined $code || carp('missing code arg ') && (return [])
carp("missing code arg ") and return []
MC/DC0%0/2
defined $code || carp('missing code arg ') && (return [])
defined $code
carp("missing code arg ")
Truth table66%2/3
A || B
A= defined $codeB= carp("missing code arg ")
| |||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | $code=~/\w/ or carp('nothing in code arg') and return []; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$code =~ /\w/ || carp('nothing in code arg') && (return [])
carp("nothing in code arg") and return []
MC/DC0%0/2
$code =~ /\w/ || carp('nothing in code arg') && (return [])
$code =~ /\w/
carp("nothing in code arg")
Truth table33%1/3
A || B
A= $code =~ /\w/B= carp("nothing in code arg")
| |||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | $public_only ||=0; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$public_only ||= 0
MC/DC0%0/1
$public_only ||= 0
$public_only
Truth table50%1/2
A
A= $public_only
| |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||
| 34 | 2 | my @_subs; | |||||||||||||||||||||||||||||
| 35 | my @subs; | ||||||||||||||||||||||||||||||
| 36 | 2 | my @lines = split( /\n/, $code); | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||
| 39 | 2 | LINE: for my $line (@lines){ | |||||||||||||||||||||||||||||
| 40 | 115 | ▶ | my $_sub = _line_defines_sub($line) or next LINE; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 41 | 12 | push @_subs, $_sub; | |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | if($public_only){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 46 | 0 | @subs = sort grep { !/^_/ } @_subs; | |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||
| 49 | else { | ||||||||||||||||||||||||||||||
| 50 | 2 | @subs = sort @_subs; | |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | 2 | return \@subs; | |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | 115 | ▶ | sub _line_defines_sub { | ||||||||||||||||||||||||||||
|
Subroutine
_line_defines_sub: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 57 | 115 | my $line = shift; | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||
| 59 | 115 | debug(" # == # line = <<<$line>>>\n"); | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||
| 61 | 115 | my $start = qr/^sub\s+|^\*|^\&/o; | |||||||||||||||||||||||||||||
| 62 | 115 | my $symbol_name = qr/[_a-zA-Z\:][_a-zA-Z\:0-9]*/o; | |||||||||||||||||||||||||||||
| 63 | 115 | my $att = qr/\s+\:\s*[a-zA-Z][\w]*/o; | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | 115 | my $end = qr/\s*{|\s*\=\s*sub\s*\{/o; | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||
| 68 | 115 | ▶ | if( $line=~/$start($symbol_name)$att?$end/sg ){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 69 | 12 | my $subname = $1; | |||||||||||||||||||||||||||||
| 70 | 12 | chomp $subname; | |||||||||||||||||||||||||||||
| 71 | 12 | debug(" # -- # subname : <<<$subname>>>\n"); | |||||||||||||||||||||||||||||
| 72 | 12 | return $subname; | |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||
| 75 | 103 | return; | |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||
| 79 | 3 | ▶ | sub _slurp { | ||||||||||||||||||||||||||||
|
Subroutine
_slurp: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||
| 80 | 3 | my $abs = shift; | |||||||||||||||||||||||||||||
| 81 | 3 | ▶ | defined $abs or confess('missing arg'); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | 3 | my $code; | |||||||||||||||||||||||||||||
| 84 | 3 | ▶ | open(FILE,'<',$abs) or confess($!);; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | while(<FILE>){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 86 | 76 | $code.=$_."\n"; | |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | close FILE or confess($!); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 89 | 3 | return $code; | |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | sub _subs_used { | ||||||||||||||||||||||||||||
|
Subroutine
_subs_used: called CC=6 SCAR=20.2
| |||||||||||||||||||||||||||||||
| 96 | 1 | my $code = shift; | |||||||||||||||||||||||||||||
| 97 | 1 | ▶ | defined $code or warn('missing code arg arg') and return {}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
defined $code || warn('missing code arg arg') && (return {})
warn "missing code arg arg" and return {}
MC/DC0%0/2
defined $code || warn('missing code arg arg') && (return {})
defined $code
warn "missing code arg arg"
Truth table33%1/3
A || B
A= defined $codeB= warn "missing code arg arg"
| |||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | $code=~/\w/ or carp('nothing in code arg') and return {}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$code =~ /\w/ || carp('nothing in code arg') && (return {})
carp("nothing in code arg") and return {}
MC/DC0%0/2
$code =~ /\w/ || carp('nothing in code arg') && (return {})
$code =~ /\w/
carp("nothing in code arg")
Truth table33%1/3
A || B
A= $code =~ /\w/B= carp("nothing in code arg")
| |||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | 1 | my $sub={}; | |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | while($code=~/(->[a-zA-Z_]+[\w]*|[a-zA-Z_]+[\w]*\()/sg){ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 103 | 4 | my $_sub = $1; | |||||||||||||||||||||||||||||
| 104 | 4 | $_sub=~s/^\>|\($//g; | |||||||||||||||||||||||||||||
| 105 | 4 | $sub->{$_sub}++; | |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | 1 | return $sub; | |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||
| 113 | 1 | ▶ | sub subs_used { | ||||||||||||||||||||||||||||
|
Subroutine
subs_used: called CC=4 SCAR=15.5
Pod
documented
| |||||||||||||||||||||||||||||||
| 114 | 1 | my ($abs_file) = @_; | |||||||||||||||||||||||||||||
| 115 | 1 | ▶ | defined $abs_file or confess('missing file arg'); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||
| 117 | 1 | ▶ | -f $abs_file or warn("File [$abs_file] is not a file.") and return {}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
-f $abs_file || warn("File [$abs_file] is not a file.") && (return {})
warn "File [$abs_file] is not a file." and return {}
MC/DC0%0/2
-f $abs_file || warn("File [$abs_file] is not a file.") && (return {})
-f $abs_file
warn "File [$abs_file] is not a file."
Truth table33%1/3
A || B
A= -f $abs_fileB= warn "File [$abs_file] is not a file."
| |||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||
| 119 | 1 | my $code = _slurp($abs_file); | |||||||||||||||||||||||||||||
| 120 | 1 | my $sub = _subs_used($code); | |||||||||||||||||||||||||||||
| 121 | 1 | return $sub; | |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||
| 126 | 1 | 1; | |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||||