lib/Acme/Incorporated.pm

filter: Statementstmt 100% 50 / 50 Branchbran 87.5% 14 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.3% 12 / 13 Podpod 100% 4 / 4 totaltotal 96.3% 80 / 83 CC 10 SCAR 9.7
CC
10
Cov
97%
breaks_when_needed
5.0
bad_product
4.0
_fake_module_fh
2.0
CRAP 2.6
↑ Summary
1 package Acme::Incorporated;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 $VERSION = '1.00';
9  
10 sub import
11 1 ▶{
Subroutine import: called CC=1 SCAR=0.0
12 1 unshift @INC, \&fine_products;
13 }
14  
15 sub fine_products
16 4 ▶{
Subroutine fine_products: called CC=2 SCAR=6.9
Pod documented
17 4 my ($code, $module) = @_;
18 4 (my $modfile = $module . '.pm') =~ s{::}{/}g;
19 4 my $fh = bad_product()->( $module, $modfile );
20  
21 4 ▶ return unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 1 3 4
22  
23 3 $INC{$modfile} = 1;
24 3 $fh->seek( 0, 0 );
25  
26 3 return $fh;
27 }
28  
29 sub empty_box
30 2 ▶{
Subroutine empty_box: called CC=1 SCAR=0.0
Pod documented
31 2 my ($module, $modpath) = @_;
32  
33 2 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 2 ▶{
Subroutine breaks_when_needed: called CC=5 SCAR=16.1
Pod documented
50 2 my ($module, $modfile) = @_;
51  
52 2 my $file;
53 2 local @INC = @INC;
54  
55 2 for my $path (@INC)
56 {
57 12 local @ARGV = File::Spec->catfile( $path, $modfile );
58 12 ▶ next unless -e $ARGV[0];
Branch: 1 branch
BranchTrueFalseTotal
unless -e $ARGV[0] 11 1 12
59  
60 1 ▶ $file = do { local $/; <> } or return;
Branch: 1 branch
BranchTrueFalseTotal
$file = do { local $/; readline ARGV } or return 1 0 1
61 }
62  
63 2 ▶ return unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 1 1 2
64  
65 1 $file =~ s/(while\s*\()/$1 Acme::Incorporated::breaks() && /g;
66 1 $file =~ s[(for[^;]+{)(\s*)]
67 [$1$2last unless Acme::Incorporated::breaks();$2]xsg;
68  
69 1 return _fake_module_fh( $file );
70 }
71  
72 sub out_of_stock
73 1 ▶{
Subroutine out_of_stock: called CC=1 SCAR=0.0
Pod documented
74 1 my ($module, $modfile) = @_;
75  
76 1 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 4 ▶{
Subroutine _fake_module_fh: called CC=2 SCAR=7.0
85 4 my $text = shift;
86 4 ▶ my $fh = IO::File->new_tmpfile() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new_tmpfile or return 4 0 4
87  
88 4 $fh->print( $text );
89 4 $fh->seek( 0, 0 );
90  
91 4 return $fh;
92 }
93  
94 sub bad_product
95 2001 ▶{
Subroutine bad_product: called CC=4 SCAR=13.9
96 2001 my $weight = rand();
97  
98 2001 ▶ return \&empty_box if $weight <= 0.10;
Branch: 1 branch
BranchTrueFalseTotal
if $weight <= "0.1" 210 1791 2001
99 1791 ▶ return \&breaks_when_needed if $weight <= 0.20;
Branch: 1 branch
BranchTrueFalseTotal
if $weight <= "0.2" 185 1606 1791
100 1606 ▶ return \&out_of_stock if $weight <= 0.30;
Branch: 1 branch
BranchTrueFalseTotal
if $weight <= "0.3" 213 1393 1606
101  
102 1393 ▶ return sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
103 }
104  
105 sub breaks
106 1000 ▶{
Subroutine breaks: called CC=1 SCAR=0.0
107 1000 return rand() <= 0.10;
108 }
109  
110 2 1;
111 __END__
↑ Summary