| 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] || ''
MC/DC100%1/1
$_[0] || ''
$_[0]
Truth table100%2/2
A
A= $_[0]
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 34 | 8 | push @flags, $_; | |||||||||||||||||||||||||||
| 35 | 8 | $flags{$_} = 1; | |||||||||||||||||||||||||||
| 36 | 8 | $key = $_; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | else { | ||||||||||||||||||||||||||||
| 39 | 1 | ▶ | $flags{$key} = $_ if $key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$default ||= 0
$default
Truth table100%2/2
A
A= $default
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | 5917 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 84 | 5917 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 1045 | *$self->{$field} = shift; | |||||||||||||||||||||||||||
| 86 | 1045 | return $self; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 4872 | ▶ | return $default unless exists *$self->{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 3611 | 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 102 | 3560 | ▶ | *$self->{$field} = | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 103 | ref($default) eq 'ARRAY' ? [] : | ||||||||||||||||||||||||||||
| 104 | ref($default) eq 'HASH' ? {} : | ||||||||||||||||||||||||||||
| 105 | $default; | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 10232 | ▶ | return *$self->{$field} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
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 | 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
| |||||||||||||||||||||||||||||
| 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 | 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 192 | 0 | } keys %{"$class\::"}; | |||||||||||||||||||||||||||
| 193 | 0 | return (%methods); | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 58 | 1; | |||||||||||||||||||||||||||