All/Base.pm

filter: Statementstmt 58.0% 137 / 236 Branchbran 38.8% 28 / 72 Conditioncond 50.0% 7 / 14 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 68.8% 31 / 45 Podpod 0.0% 0 / 13 totaltotal 53.3% 207 / 388 CC 63 SCAR 16.9
CC
63
Cov
53%
import
15.2
import
15.2
mixin_import
10.8
CRAP 5.4
« All/File.pm ↑ Summary All/Pipe.pm »
1 58 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package IO::All::Base;
3  
4 58 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 427 ▶sub import {
Subroutine import: called CC=7 SCAR=27.2
7 0 ▶ my $class = shift;
Subroutine import: not called CC=7 SCAR=27.2
8 0 ▶ my $flag = $_[0] || '';
Condition50%2/4
$_[0] || ''
l!l
34780
$_[0] || ''
l!l
00
MC/DC100%1/1
$_[0] || ''
$_[0]
MC/DC0%0/1
$_[0] || ''
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
9 0 my $package = caller;
10 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 0 ▶ if ($flag eq '-base') {
Branch: 4 branches
BranchTrueFalseTotal
if ($flag eq '-base') { } 340 87 427
elsif ($flag eq '-mixin') { } 0 87 87
if ($flag eq '-base') { } 0 0 0
elsif ($flag eq '-mixin') { } 0 0 0
12 0 push @{$package . "::ISA"}, $class;
13 0 *{$package . "::$_"} = \&$_
14 0 for qw'field const option chain proxy proxy_open';
15 }
16 elsif ($flag eq -mixin) {
17 0 mixin_import(scalar(caller(0)), $class, @_);
18 }
19 else {
20 0 my @flags = @_;
21 0 for my $export (@{$class . '::EXPORT'}) {
22 0 *{$package . "::$export"} = $export eq 'io'
23 ? $class->_generate_constructor(@flags)
24 0 ▶ : \&{$class . "::$export"};
Branch: 2 branches
BranchTrueFalseTotal
$export eq 'io' ? : 63 0 63
$export eq 'io' ? : 0 0 0
25 }
26 }
27 }
28  
29 63 ▶sub _generate_constructor {
Subroutine _generate_constructor: called CC=4 SCAR=18.5
30 0 ▶ my $class = shift;
Subroutine _generate_constructor: not called CC=4 SCAR=18.5
31 0 my (@flags, %flags, $key);
32 0 for (@_) {
33 0 ▶ if (s/^-//) {
Branch: 2 branches
BranchTrueFalseTotal
if (s/^-//) { } 8 1 9
if (s/^-//) { } 0 0 0
34 0 push @flags, $_;
35 0 $flags{$_} = 1;
36 0 $key = $_;
37 }
38 else {
39 0 ▶ $flags{$key} = $_ if $key;
Branch: 2 branches
BranchTrueFalseTotal
if $key 1 0 1
if $key 0 0 0
40 }
41 }
42 0 my $constructor;
43 636 ▶ $constructor = sub {
Subroutine __ANON__: called CC=2 SCAR=9.2
44 0 ▶ my $self = $class->new(@_);
Subroutine __ANON__: not called CC=2 SCAR=9.2
45 0 for (@flags) {
46 0 $self->$_($flags{$_});
47 }
48 0 $self->_constructor($constructor);
49 0 return $self;
50 }
51 0 }
52  
53 777 ▶sub _init {
Subroutine _init: called CC=1 SCAR=1.2
54 0 ▶ my $self = shift;
Subroutine _init: not called CC=1 SCAR=1.2
55 0 $self->io_handle(undef);
56 0 $self->is_open(0);
57 0 return $self;
58 }
59  
60 #===============================================================================
61 # Closure generating functions
62 #===============================================================================
63 560 ▶sub option {
Subroutine option: called CC=2 SCAR=8.6
Pod undocumented
64 0 ▶ my $package = caller;
Subroutine option: not called CC=2 SCAR=8.6
Pod undocumented
65 0 my ($field, $default) = @_;
66 0 ▶ $default ||= 0;
Condition50%2/4
$default ||= 0
l!l
75485
$default ||= 0
l!l
00
MC/DC100%1/1
$default ||= 0
$default
MC/DC0%0/1
$default ||= 0
$default
Truth table100%2/2
A
A= $default
Aresult
11
00
Truth table0%0/2
A
A= $default
Aresult
11
00
67 0 field("_$field", $default);
68 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
69 0 *{"${package}::$field"} =
70 25 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=9.2
71 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=2 SCAR=9.2
72 0 ▶ *$self->{"_$field"} = @_ ? shift(@_) : 1;
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 6 19 25
@_ ? : 0 0 0
73 0 return $self;
74 0 };
75 }
76  
77 373 ▶sub chain {
Subroutine chain: called CC=1 SCAR=0.9
Pod undocumented
78 0 ▶ my $package = caller;
Subroutine chain: not called CC=1 SCAR=0.9
Pod undocumented
79 0 my ($field, $default) = @_;
80 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
81 0 *{"${package}::$field"} =
82 5746 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
83 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=3 SCAR=14.2
84 0 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) 1050 4696 5746
if (@_) 0 0 0
85 0 *$self->{$field} = shift;
86 0 return $self;
87 }
88 0 ▶ return $default unless exists *$self->{$field};
Branch: 2 branches
BranchTrueFalseTotal
unless exists *$self->{$field} 1265 3431 4696
unless exists *$self->{$field} 0 0 0
89 0 return *$self->{$field};
90 0 };
91 }
92  
93 1173 ▶sub field {
Subroutine field: called CC=2 SCAR=9.3
Pod undocumented
94 0 ▶ my $package = caller;
Subroutine field: not called CC=2 SCAR=9.3
Pod undocumented
95 0 my ($field, $default) = @_;
96 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
97 0 ▶ return if defined &{"${package}::$field"};
Branch: 2 branches
BranchTrueFalseTotal
if defined &{"${package}::$field";} 0 1173 1173
if defined &{"${package}::$field";} 0 0 0
98 0 *{"${package}::$field"} =
99 10607 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=21.9
100 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=5 SCAR=21.9
101 0 ▶ unless (exists *$self->{$field}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists *$self->{$field}) 3716 6891 10607
unless (exists *$self->{$field}) 0 0 0
102 0 ▶ *$self->{$field} =
Branch: 4 branches
BranchTrueFalseTotal
ref $default eq 'ARRAY' ? : 258 3458 3716
ref $default eq 'HASH' ? : 0 3458 3458
ref $default eq 'ARRAY' ? : 0 0 0
ref $default eq 'HASH' ? : 0 0 0
103 ref($default) eq 'ARRAY' ? [] :
104 ref($default) eq 'HASH' ? {} :
105 $default;
106 }
107 0 ▶ return *$self->{$field} unless @_;
Branch: 2 branches
BranchTrueFalseTotal
unless @_ 6595 4012 10607
unless @_ 0 0 0
108 0 *$self->{$field} = shift;
109 0 };
110 }
111  
112 95 ▶sub const {
Subroutine const: called CC=2 SCAR=8.6
Pod undocumented
113 0 ▶ my $package = caller;
Subroutine const: not called CC=2 SCAR=8.6
Pod undocumented
114 0 my ($field, $default) = @_;
115 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
116 0 ▶ return if defined &{"${package}::$field"};
Branch: 2 branches
BranchTrueFalseTotal
if defined &{"${package}::$field";} 0 95 95
if defined &{"${package}::$field";} 0 0 0
117 0 ▶ *{"${package}::$field"} = sub { $default };
Subroutine __ANON__: called CC=1 SCAR=0.6
118 }
119  
120 348 ▶sub proxy {
Subroutine proxy: called CC=2 SCAR=7.0
Pod undocumented
121 348 my $package = caller;
122 348 my ($proxy) = @_;
123 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
124 348 ▶ return if defined &{"${package}::$proxy"};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"${package}::$proxy";} 0 348 348
125 348 *{"${package}::$proxy"} =
126 7 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
127 7 my $self = shift;
128 7 my @return = $self->io_handle->$proxy(@_);
129 7 $self->_error_check;
130 7 ▶ wantarray ? @return : $return[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 7 7
131 348 };
132 }
133  
134 356 ▶sub proxy_open {
Subroutine proxy_open: called CC=4 SCAR=13.9
Pod undocumented
135 356 my $package = caller;
136 356 my ($proxy, @args) = @_;
137 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
138 356 ▶ return if defined &{"${package}::$proxy"};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"${package}::$proxy";} 0 356 356
139 60 ▶ my $method = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
140 60 my $self = shift;
141 60 $self->_assert_open(@args);
142 60 my @return = $self->io_handle->$proxy(@_);
143 60 $self->_error_check;
144 60 ▶ wantarray ? @return : $return[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 60 60
145 356 };
146 356 *{"$package\::$proxy"} =
147 (@args and $args[0] eq '>') ?
148 57 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
149 57 my $self = shift;
150 57 $self->$method(@_);
151 57 return $self;
152 }
153 356 ▶ : $method;
Branch: 1 branch
BranchTrueFalseTotal
@args && $args[0] eq '>' ? : 116 240 356
Condition100%3/3
@args and $args[0] eq ">"
!ll&&!rl&&r
66174116
MC/DC100%2/2
@args and $args[0] eq ">"
@args $args[0] eq ">"
Truth table100%3/3
A and B
A= @argsB= $args[0] eq ">"
ABresult
0X0
100
111
154 }
155  
156 0 ▶sub mixin_import {
Subroutine mixin_import: not called CC=4 SCAR=23.7
Pod undocumented
157 0 my $target_class = shift;
158 0 ▶ $target_class = caller(0)
Branch: 1 branch
BranchTrueFalseTotal
if $target_class eq "mixin" 0 0 0
159 if $target_class eq 'mixin';
160 0 ▶ my $mixin_class = shift
Branch: 1 branch
BranchTrueFalseTotal
my $mixin_class = shift() or die "Nothing to mixin" 0 0 0
161 or die "Nothing to mixin";
162 0 eval "require $mixin_class";
163 0 my $pseudo_class = CORE::join '-', $target_class, $mixin_class;
164 0 my %methods = mixin_methods($mixin_class);
165 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
166 58 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
167 0 @{"$pseudo_class\::ISA"} = @{"$target_class\::ISA"};
168 0 @{"$target_class\::ISA"} = ($pseudo_class);
169 0 for (keys %methods) {
170 0 *{"$pseudo_class\::$_"} = $methods{$_};
171 }
172 }
173  
174 0 ▶sub mixin_methods {
Subroutine mixin_methods: not called CC=2 SCAR=12.6
Pod undocumented
175 0 my $mixin_class = shift;
176 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
177 0 my %methods = all_methods($mixin_class);
178 map {
179 0 $methods{$_}
180 0 ? ($_, \ &{"$methods{$_}\::$_"})
181 0 ▶ : ($_, \ &{"$mixin_class\::$_"})
Branch: 1 branch
BranchTrueFalseTotal
$methods{$_} ? : 0 0 0
182 } (keys %methods);
183 }
184  
185 0 ▶sub all_methods {
Subroutine all_methods: not called CC=2 SCAR=13.4
Pod undocumented
186 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
187 0 my $class = shift;
188 my %methods = map {
189 0 ($_, $class)
190 } grep {
191 0 ▶ defined &{"$class\::$_"} and not /^_/
Condition0%0/3
defined &{"${class}::$_";} && !/^_/
!ll&&!rl&&r
000
MC/DC0%0/2
defined &{"${class}::$_";} && !/^_/
defined &{"${class}::$_";} !/^_/
Truth table0%0/3
A && not(B)
A= defined &{"${class}::$_";}B= !/^_/
ABresult
0X0
100
111
192 0 } keys %{"$class\::"};
193 0 return (%methods);
194 }
195  
196 58 1;
« All/File.pm ↑ Summary All/Pipe.pm »