| 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] || ''
$_[0] || ''
MC/DC100%1/1
$_[0] || ''
$_[0]
MC/DC0%0/1
$_[0] || ''
$_[0]
Truth table100%2/2
A
A= $_[0]
Truth table0%0/2
A
A= $_[0]
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 34 | 0 | push @flags, $_; | |||||||||||||||||||||||||||
| 35 | 0 | $flags{$_} = 1; | |||||||||||||||||||||||||||
| 36 | 0 | $key = $_; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | else { | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $flags{$key} = $_ if $key; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
$default ||= 0
MC/DC100%1/1
$default ||= 0
$default
MC/DC0%0/1
$default ||= 0
$default
Truth table100%2/2
A
A= $default
Truth table0%0/2
A
A= $default
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 85 | 0 | *$self->{$field} = shift; | |||||||||||||||||||||||||||
| 86 | 0 | return $self; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | return $default unless exists *$self->{$field}; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | *$self->{$field} = | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 103 | ref($default) eq 'ARRAY' ? [] : | ||||||||||||||||||||||||||||
| 104 | ref($default) eq 'HASH' ? {} : | ||||||||||||||||||||||||||||
| 105 | $default; | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | return *$self->{$field} unless @_; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
@args and $args[0] eq ">"
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 ">"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 159 | if $target_class eq 'mixin'; | ||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my $mixin_class = shift | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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}::$_";} && !/^_/
MC/DC0%0/2
defined &{"${class}::$_";} && !/^_/
defined &{"${class}::$_";}
!/^_/
Truth table0%0/3
A && not(B)
A= defined &{"${class}::$_";}B= !/^_/
| |||||||||||||||||||||||||||||
| 192 | 0 | } keys %{"$class\::"}; | |||||||||||||||||||||||||||
| 193 | 0 | return (%methods); | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 58 | 1; | |||||||||||||||||||||||||||