lib/LEOCHARRE/PMSubs.pm

filter: Statementstmt 97.4% 75 / 77 Branchbran 65.6% 21 / 32 Conditioncond 35.7% 10 / 28 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 72.5% 119 / 164 CC 26 SCAR 18.4
CC
26
Cov
77%
_subs_defined
10.8
_subs_used
7.5
subs_defined
6.1
CRAP 6.3
« lib/LEOCHARRE/PMInspect.pm ↑ Summary lib/LEOCHARRE/DEBUG2.pm »
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
BranchTrueFalseTotal
defined $abs_file or confess("missing file arg") 2 0 2
16 2 ▶ $public_only ||=0;
Condition50%1/2
$public_only ||= 0
l!l
02
MC/DC0%0/1
$public_only ||= 0
$public_only
Truth table50%1/2
A
A= $public_only
Aresult
11
00
17  
18 2 ▶ -f $abs_file or warn("File [$abs_file] is not a file.") and return [];
Branch: 1 branch
BranchTrueFalseTotal
-f $abs_file or warn "File [$abs_file] is not a file." and return [] 2 0 2
Condition25%1/4
-f $abs_file || warn("File [$abs_file] is not a file.") && (return [])
l!l
20
warn "File [$abs_file] is not a file." and return []
!ll
00
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."
ABresult
1X1
011
000
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
BranchTrueFalseTotal
defined $code or carp("missing code arg ") and return [] 2 1 3
Condition75%3/4
defined $code || carp('missing code arg ') && (return [])
l!l
21
carp("missing code arg ") and return []
!ll
01
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 ")
ABresult
1X1
011
000
29 2 ▶ $code=~/\w/ or carp('nothing in code arg') and return [];
Branch: 1 branch
BranchTrueFalseTotal
$code =~ /\w/ or carp("nothing in code arg") and return [] 2 0 2
Condition25%1/4
$code =~ /\w/ || carp('nothing in code arg') && (return [])
l!l
20
carp("nothing in code arg") and return []
!ll
00
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")
ABresult
1X1
011
000
30 2 ▶ $public_only ||=0;
Condition50%1/2
$public_only ||= 0
l!l
02
MC/DC0%0/1
$public_only ||= 0
$public_only
Truth table50%1/2
A
A= $public_only
Aresult
11
00
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
BranchTrueFalseTotal
my $_sub = _line_defines_sub($line) or next LINE 12 103 115
41 12 push @_subs, $_sub;
42 }
43  
44  
45 2 ▶ if($public_only){
Branch: 1 branch
BranchTrueFalseTotal
if ($public_only) { } 0 2 2
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
BranchTrueFalseTotal
if ($line =~ /$start($symbol_name)$att?$end/gs) 12 103 115
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
BranchTrueFalseTotal
defined $abs or confess("missing arg") 3 0 3
82
83 3 my $code;
84 3 ▶ open(FILE,'<',$abs) or confess($!);;
Branch: 1 branch
BranchTrueFalseTotal
open FILE, "<", $abs or confess($!) 3 0 3
85 3 ▶ while(<FILE>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 76 3 79
86 76 $code.=$_."\n";
87 }
88 3 ▶ close FILE or confess($!);
Branch: 1 branch
BranchTrueFalseTotal
close FILE or confess($!) 3 0 3
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
BranchTrueFalseTotal
defined $code or warn "missing code arg arg" and return {} 1 0 1
Condition25%1/4
defined $code || warn('missing code arg arg') && (return {})
l!l
10
warn "missing code arg arg" and return {}
!ll
00
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"
ABresult
1X1
011
000
98 1 ▶ $code=~/\w/ or carp('nothing in code arg') and return {};
Branch: 1 branch
BranchTrueFalseTotal
$code =~ /\w/ or carp("nothing in code arg") and return {} 1 0 1
Condition25%1/4
$code =~ /\w/ || carp('nothing in code arg') && (return {})
l!l
10
carp("nothing in code arg") and return {}
!ll
00
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")
ABresult
1X1
011
000
99
100 1 my $sub={};
101  
102 1 ▶ while($code=~/(->[a-zA-Z_]+[\w]*|[a-zA-Z_]+[\w]*\()/sg){
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /(->[a-zA-Z_]+[\w]*|[a-zA-Z_]+[\w]*\()/gs) 4 1 5
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
BranchTrueFalseTotal
defined $abs_file or confess("missing file arg") 1 0 1
116  
117 1 ▶ -f $abs_file or warn("File [$abs_file] is not a file.") and return {};
Branch: 1 branch
BranchTrueFalseTotal
-f $abs_file or warn "File [$abs_file] is not a file." and return {} 1 0 1
Condition25%1/4
-f $abs_file || warn("File [$abs_file] is not a file.") && (return {})
l!l
10
warn "File [$abs_file] is not a file." and return {}
!ll
00
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."
ABresult
1X1
011
000
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__
« lib/LEOCHARRE/PMInspect.pm ↑ Summary lib/LEOCHARRE/DEBUG2.pm »