All/Base.pm

filter: Statementstmt 82.5% 137 / 166 Branchbran 60.8% 28 / 46 Conditioncond 100% 7 / 7 MC/DCmcdc 100% 4 / 4 Subroutinesub 91.1% 31 / 34 Podpod 0.0% 0 / 9 totaltotal 77.8% 207 / 266 SCAR 37.4
CC
32
Cov
79%
mixin_import
10.8
import
7.2
all_methods
6.0
CRAP 42.1
« All/Socket.pm ↑ Summary All/Filesys.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 sub import {
7 427 ▶ my $class = shift;
Subroutine import: called CC=7 SCAR=19.7
8 427 ▶ my $flag = $_[0] || '';
Condition100%2/2
$_[0] || ''
l!l
34780
MC/DC100%1/1
$_[0] || ''
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
9 427 my $package = caller;
10 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 427 ▶ if ($flag eq '-base') {
Branch: 2 branches
BranchTrueFalseTotal
if ($flag eq '-base') { } 340 87 427
elsif ($flag eq '-mixin') { } 0 87 87
12 340 push @{$package . "::ISA"}, $class;
13 2040 *{$package . "::$_"} = \&$_
14 340 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 87 my @flags = @_;
21 87 for my $export (@{$class . '::EXPORT'}) {
22 63 *{$package . "::$export"} = $export eq 'io'
23 ? $class->_generate_constructor(@flags)
24 63 ▶ : \&{$class . "::$export"};
Branch: 1 branch
BranchTrueFalseTotal
$export eq 'io' ? : 63 0 63
25 }
26 }
27 }
28  
29 sub _generate_constructor {
30 63 ▶ my $class = shift;
Subroutine _generate_constructor: called CC=4 SCAR=13.9
31 63 my (@flags, %flags, $key);
32 63 for (@_) {
33 9 ▶ if (s/^-//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^-//) { } 8 1 9
34 8 push @flags, $_;
35 8 $flags{$_} = 1;
36 8 $key = $_;
37 }
38 else {
39 1 ▶ $flags{$key} = $_ if $key;
Branch: 1 branch
BranchTrueFalseTotal
if $key 1 0 1
40 }
41 }
42 63 my $constructor;
43 $constructor = sub {
44 632 ▶ my $self = $class->new(@_);
Subroutine __ANON__: called CC=2 SCAR=6.9
45 632 for (@flags) {
46 12 $self->$_($flags{$_});
47 }
48 631 $self->_constructor($constructor);
49 631 return $self;
50 }
51 63 }
52  
53 sub _init {
54 772 ▶ my $self = shift;
Subroutine _init: called CC=1 SCAR=0.0
55 772 $self->io_handle(undef);
56 772 $self->is_open(0);
57 772 return $self;
58 }
59  
60 #===============================================================================
61 # Closure generating functions
62 #===============================================================================
63 sub option {
64 560 ▶ my $package = caller;
Subroutine option: called CC=2 SCAR=6.9
Pod undocumented
65 560 my ($field, $default) = @_;
66 560 ▶ $default ||= 0;
Condition100%2/2
$default ||= 0
l!l
75485
MC/DC100%1/1
$default ||= 0
$default
Truth table100%2/2
A
A= $default
Aresult
11
00
67 560 field("_$field", $default);
68 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
69 560 *{"${package}::$field"} =
70 sub {
71 25 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
72 25 ▶ *$self->{"_$field"} = @_ ? shift(@_) : 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 6 19 25
73 25 return $self;
74 560 };
75 }
76  
77 sub chain {
78 373 ▶ my $package = caller;
Subroutine chain: called CC=1 SCAR=0.0
Pod undocumented
79 373 my ($field, $default) = @_;
80 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
81 373 *{"${package}::$field"} =
82 sub {
83 6157 ▶ my $self = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
84 6157 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1045 5112 6157
85 1045 *$self->{$field} = shift;
86 1045 return $self;
87 }
88 5112 ▶ return $default unless exists *$self->{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless exists *$self->{$field} 1261 3851 5112
89 3851 return *$self->{$field};
90 373 };
91 }
92  
93 sub field {
94 1173 ▶ my $package = caller;
Subroutine field: called CC=2 SCAR=6.9
Pod undocumented
95 1173 my ($field, $default) = @_;
96 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
97 1173 ▶ return if defined &{"${package}::$field"};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"${package}::$field";} 0 1173 1173
98 1173 *{"${package}::$field"} =
99 sub {
100 10232 ▶ my $self = shift;
Subroutine __ANON__: called CC=5 SCAR=16.1
101 10232 ▶ unless (exists *$self->{$field}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists *$self->{$field}) 3560 6672 10232
102 3560 ▶ *$self->{$field} =
Branch: 2 branches
BranchTrueFalseTotal
ref $default eq 'ARRAY' ? : 122 3438 3560
ref $default eq 'HASH' ? : 0 3438 3438
103 ref($default) eq 'ARRAY' ? [] :
104 ref($default) eq 'HASH' ? {} :
105 $default;
106 }
107 10232 ▶ return *$self->{$field} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 6242 3990 10232
108 3990 *$self->{$field} = shift;
109 1173 };
110 }
111  
112 sub const {
113 95 ▶ my $package = caller;
Subroutine const: called CC=2 SCAR=6.9
Pod undocumented
114 95 my ($field, $default) = @_;
115 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
116 95 ▶ return if defined &{"${package}::$field"};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{"${package}::$field";} 0 95 95
117 95 ▶ *{"${package}::$field"} = sub { $default };
Subroutine __ANON__: called CC=1 SCAR=0.0
118 }
119  
120 sub proxy {
121 348 ▶ my $package = caller;
Subroutine proxy: called CC=2 SCAR=7.0
Pod undocumented
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 sub {
127 7 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
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 sub proxy_open {
135 356 ▶ my $package = caller;
Subroutine proxy_open: called CC=4 SCAR=13.9
Pod undocumented
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 my $method = sub {
140 60 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
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 sub {
149 57 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
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 sub mixin_import {
157 0 ▶ my $target_class = shift;
Subroutine mixin_import: not called CC=4 SCAR=23.7
Pod undocumented
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 sub mixin_methods {
175 0 ▶ my $mixin_class = shift;
Subroutine mixin_methods: not called CC=2 SCAR=12.6
Pod undocumented
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 sub all_methods {
186 58 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
187 0 ▶ my $class = shift;
Subroutine all_methods: not called CC=2 SCAR=17.9
Pod undocumented
188 my %methods = map {
189 0 ($_, $class)
190 } grep {
191 0 ▶ defined &{"$class\::$_"} and not /^_/
Branch: 1 branch
BranchTrueFalseTotal
defined &{"${class}::$_";} and not /^_/ 0 0 0
192 0 } keys %{"$class\::"};
193 0 return (%methods);
194 }
195  
196 58 1;
« All/Socket.pm ↑ Summary All/Filesys.pm »