blib/lib/Acme/Pills.pm

filter: Statementstmt 28.0% 14 / 50 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 30.7% 4 / 13 Podpod 100% 6 / 6 totaltotal 28.2% 24 / 85 CC 10 SCAR 25.0
CC
10
Cov
21%
breaks_when_needed
30.0
bad_product
20.0
fine_products
6.0
CRAP 12.2
↑ Summary
1 package Acme::Pills;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $VERSION = '0.01';
9  
10 sub import
11 0 ▶{
Subroutine import: not called CC=1 SCAR=6.9
12 0 unshift @INC, \&fine_products;
13 }
14  
15 sub fine_products
16 0 ▶{
Subroutine fine_products: not called CC=2 SCAR=17.9
Pod documented
17 0 my ($code, $module) = @_;
18 0 (my $modfile = $module . '.pm') =~ s{::}{/}g;
19 0 my $fh = bad_product()->( $module, $modfile );
20  
21 0 ▶ return unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
22  
23 0 $INC{$modfile} = 1;
24 0 $fh->seek( 0, 0 );
25  
26 0 return $fh;
27 }
28  
29 sub empty_box
30 0 ▶{
Subroutine empty_box: not called CC=1 SCAR=6.9
Pod documented
31 0 my ($module, $modpath) = @_;
32  
33 0 return _fake_module_fh(<<END_MODULE);
34 package $module;
35  
36 sub DESTROY {}
37  
38 sub AUTOLOAD
39 {
40 return 1;
41 }
42  
43 1;
44 END_MODULE
45  
46 }
47  
48 sub breaks_when_needed
49 0 ▶{
Subroutine breaks_when_needed: not called CC=5 SCAR=34.0
Pod documented
50 0 my ($module, $modfile) = @_;
51  
52 0 my $file;
53 0 local @INC = @INC;
54  
55 0 for my $path (@INC)
56 {
57 0 local @ARGV = File::Spec->catfile( $path, $modfile );
58 0 ▶ next unless -e $ARGV[0];
Branch: 1 branch
BranchTrueFalseTotal
unless -e $ARGV[0] 0 0 0
59  
60 0 ▶ $file = do { local $/; <> } or return;
Branch: 1 branch
BranchTrueFalseTotal
$file = do { local $/; readline ARGV } or return 0 0 0
61 }
62  
63 0 ▶ return unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 0 0
64  
65 0 $file =~ s/(while\s*\()/$1 Acme::Incorporated::breaks() && /g;
66 0 $file =~ s[(for[^;]+{)(\s*)]
67 [$1$2last unless Acme::Incorporated::breaks();$2]xsg;
68  
69 0 return _fake_module_fh( $file );
70 }
71  
72 sub out_of_stock
73 0 ▶{
Subroutine out_of_stock: not called CC=1 SCAR=6.9
Pod documented
74 0 my ($module, $modfile) = @_;
75  
76 0 return _fake_module_fh(<<END_MODULE);
77 print "$module is out of stock at the moment.\n"
78 delete \$INC{$modfile};
79 END_MODULE
80  
81 }
82  
83 sub _fake_module_fh
84 0 ▶{
Subroutine _fake_module_fh: not called CC=2 SCAR=17.9
85 0 my $text = shift;
86 0 ▶ my $fh = IO::File->new_tmpfile() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new_tmpfile or return 0 0 0
87  
88 0 $fh->print( $text );
89 0 $fh->seek( 0, 0 );
90  
91 0 return $fh;
92 }
93  
94 sub bad_product
95 0 ▶{
Subroutine bad_product: not called CC=4 SCAR=30.0
Pod documented
96 0 my $weight = rand();
97  
98 0 ▶ return \&empty_box if $weight <= 0.10;
Branch: 1 branch
BranchTrueFalseTotal
if $weight <= "0.1" 0 0 0
99 0 ▶ return \&breaks_when_needed if $weight <= 0.20;
Branch: 1 branch
BranchTrueFalseTotal
if $weight <= "0.2" 0 0 0
100 0 ▶ return \&out_of_stock if $weight <= 0.30;
Branch: 1 branch
BranchTrueFalseTotal
if $weight <= "0.3" 0 0 0
101  
102 0 ▶ return sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
103 }
104  
105 sub breaks
106 0 ▶{
Subroutine breaks: not called CC=1 SCAR=6.9
Pod documented
107 0 return rand() <= 0.10;
108 }
109  
110 1 1;
111 __END__
↑ Summary