lib/LEOCHARRE/Dev.pm

filter: Statementstmt 42.8% 9 / 21 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 50.0% 3 / 6 Podpod n/a totaltotal 23.0% 12 / 52 CC 7 SCAR 31.1
CC
7
Cov
22%
is_pmdist
42.0
debug
6.0
_show_symbol_table
2.0
CRAP 22.4
↑ Summary lib/LEOCHARRE/PMUsed.pm »
1 package LEOCHARRE::Dev;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 $VERSION = sprintf "%d.%02d", q$Revision: 1.13 $ =~ /(\d+)/g;
6 @EXPORT_OK = qw(is_pmdist ls_pmdist pmdist_guess_name pmdist_guess_version_from);
7 @ISA = qw/Exporter/;
8 %EXPORT_TAGS = ( 'all' => \@EXPORT_OK );
9  
10  
11 $LEOCHARRE::Dev::DEBUG = 1;
12 0 ▶sub debug { print STDERR " - @_\n" if $LEOCHARRE::Dev::DEBUG; 1 }
Subroutine debug: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $LEOCHARRE::Dev::DEBUG 0 0 0
13  
14 0 ▶sub _show_symbol_table {
Subroutine _show_symbol_table: not called CC=1 SCAR=6.9
15 0 require Data::Dumper;
16
17 0 print STDERR " SYMBOL TABLE\n" . Data::Dumper::Dumper(\%LEOCHARRE::Dev::);
18 0 print STDERR "\n";
19  
20 }
21  
22 0 ▶sub is_pmdist {
Subroutine is_pmdist: not called CC=6 SCAR=37.4
23 0 my $d = shift;
24 0 require Cwd;
25 0 ▶ $d ||= Cwd::cwd();
Condition0%0/3
$d ||= Cwd::cwd()
l!l&&r!l&&!r
000
MC/DC0%0/2
$d ||= Cwd::cwd()
$d Cwd::cwd()
Truth table0%0/3
A ||= B
A= $dB= Cwd::cwd()
ABresult
1X1
011
000
26
27 0 $d = Cwd::abs_path($d);
28  
29 0 ▶ -d $d
Branch: 1 branch
BranchTrueFalseTotal
-d $d or warn "$d is not dir" and return 0 0 0
Condition0%0/5
-d $d || warn("$d is not dir") && (return)
l!l&&r!l&&!r
000
warn "$d is not dir" and return
!ll
00
MC/DC0%0/2
-d $d || warn("$d is not dir") && (return)
-d $d warn "$d is not dir"
Truth table0%0/3
A || B
A= -d $dB= warn "$d is not dir"
ABresult
1X1
011
000
30 or warn("$d is not dir")
31 and return;
32  
33 0 ▶ -f "$d/Makefile.PL"
Branch: 1 branch
BranchTrueFalseTotal
-f "$d/Makefile.PL" or warn "$d is not dist, no Makefile.PL" and return 0 0 0 0
Condition0%0/5
-f "$d/Makefile.PL" || warn("$d is not dist, no Makefile.PL") && (return 0)
l!l&&r!l&&!r
000
warn "$d is not dist, no Makefile.PL" and return 0
!ll
00
MC/DC0%0/2
-f "$d/Makefile.PL" || warn("$d is not dist, no Makefile.PL") && (return 0)
-f "$d/Makefile.PL" warn "$d is not dist, no Makefile.PL"
Truth table0%0/3
A || B
A= -f "$d/Makefile.PL"B= warn "$d is not dist, no Makefile.PL"
ABresult
1X1
011
000
34 or warn("$d is not dist, no Makefile.PL")
35 and return 0;
36  
37 0 return $d;
38 }
39  
40  
41 sub ls_pmdist {
42 my $d = shift;
43 $d ||= './';
44 my $abs_d = is_pmdist($d) or die;
45  
46 my @ls;
47 for my $distfile ( sort grep { !/CVS|\.swp$/ } split( /\n/, `find '$abs_d' -type f`) ){
48 $distfile=~s/^$abs_d\///;
49 push @ls,$distfile;
50 }
51 defined @ls or warn("nothing in $abs_d ?");
52 return @ls;
53 }
54  
55  
56 sub pmdist_guess_name {
57 my $d = shift;
58 $d ||= './';
59
60 my $abs_d = is_pmdist($d) or die;
61 $abs_d=~s/^\/.+\/devel\///;
62 print STDERR " dist nameguess $abs_d\n";
63  
64 $abs_d=~s/.+\///;
65 $abs_d=~s/\-/::/g;
66 print STDERR " returning $abs_d\n";
67 return $abs_d;
68
69 }
70  
71 sub pmdist_guess_version_from {
72 my $d = shift;
73 $d ||= './';
74 my $abs_d = is_pmdist($d) or die;
75  
76 if( my $distname = pmdist_guess_name($abs_d) ){
77 $distname=~s/::/\//g;
78 $distname.='.pm';
79 my $pm = $distname;
80 if (-f "$abs_d/$distname"){
81 debug("found $abs_d/$distname.");
82  
83 return $distname;
84 }
85 elsif( -f "$abs_d/lib/$distname"){
86 debug("found $abs_d/lib/$distname.");
87  
88 return "lib/$distname";
89 }
90 debug("Got distname $distname but could not match a file.");
91 }
92  
93 debug("did not get distname from pmdist_guess_name()");
94
95 my @pms = grep { /\.pm$/ and !/^blib\// and !/^t\// } ls_pmdist($d);
96 @pms and scalar @pms or return;
97  
98 my @libpms = grep { /^lib\// } @pms;
99 if (@libpms and scalar @libpms ){ # return first
100 return $libpms[0];
101 }
102  
103 # any other?
104 return $pms[0];
105  
106  
107 #my @pm = grep { /\.pm$/ } ls_pmdist($d) or return;
108 #my $first = shift @pm;
109 #return $first;
110  
111 }
112  
113  
114  
115 1;
116  
117  
118 __END__
↑ Summary lib/LEOCHARRE/PMUsed.pm »