Common/Handle.pm

filter: Statementstmt 56.1% 50 / 89 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 68.4% 13 / 19 Podpod 0.0% 0 / 4 totaltotal 39.6% 63 / 159 CC 18 SCAR 38.0
CC
18
Cov
40%
refresh
132.0
AUTOLOAD
17.2
say
12.0
CRAP 44.7
↑ Summary Common.pm »
1 1 ▶use Object::Pad ':experimental(:all)';
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package IO::Handle::Common::Handle;
4  
5 class IO::Handle::Common::Handle : does(IO::Handle::Common::Base);
6  
7 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶no warnings 'experimental::re_strict';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use re 'strict';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Const::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Unicode::UTF8;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use List::Util qw'any none first';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Path::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use IO::Handle::Common::Base qw'refstr';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 const our $DEFAULT_LAYER => 'encoding(UTF-8)';
22  
23 1 ▶use open ':std', IO => $DEFAULT_LAYER;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 field $charset : param = 'UTF-8';
26 1 field $fileno;
27 field $handle : reader(fh)
28 0 ▶ ; # TODO: decipher AUTOLOAD logic that led to charset reader here
Subroutine fh: not called CC=1 SCAR=2.6
Pod undocumented
29 1 field $path;
30 field $mode : param = ">";
31 1 field $autoflush : param = 1;
32  
33 1 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=4 SCAR=28.4
34 0 our $AUTOLOAD;
35  
36 0 my $invoke = shift;
37 0 const my $meth_re => qr!^.*::!;
38 0 my $method = ( $AUTOLOAD =~ s/$meth_re//r );
39  
40 0 ▶ if ( blessed $invoke && $invoke->isa('IO::Handle::Common::Handle') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($invoke) and $invoke->isa('IO::Handle::Common::Handle')) { } 0 0 0
Condition0%0/3
builtin::blessed($invoke) and $invoke->isa("IO::Handle::Common::Handle")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($invoke) and $invoke->isa("IO::Handle::Common::Handle")
builtin::blessed($invoke) $invoke->isa("IO::Handle::Common::Handle")
Truth table0%0/3
A and B
A= builtin::blessed($invoke)B= $invoke->isa("IO::Handle::Common::Handle")
ABresult
0X0
100
111
41 0 ▶ if ( my $charset = $invoke->fh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $charset = $invoke->fh) 0 0 0
42 0 $invoke->fh->$method(@_);
43 }
44 }
45 else {
46 0 die "No class common method '$method' ($AUTOLOAD)";
47 }
48 }
49  
50 1 ADJUST : params (:$fn //= undef, :$fh //= undef, :$fd //= undef) {
51 my @arg = ( $fn, $fh, $fd );
52  
53 die "Only one of the following can be defined: \$fn, \$fh, \$fd"
54 if scalar( ( grep { defined $_ } @arg ) > 1 );
55  
56 $handle = IO::Handle->new;
57  
58 if ($fn) {
59 $path = Path::Tiny::path($fn);
60 $handle = $path->filehandle($mode);
61 }
62 elsif ($fh) {
63 $handle = $fh;
64 $fileno = fileno($fh);
65 }
66 elsif ($fd) {
67 $handle = FileHandle->new_from_fd( $fd, $mode );
68 $handle->binmode($IO::Handle::Common::Handle::DEFAULT_LAYER);
69 $fileno = $fd;
70 }
71  
72 $handle->autoflush($autoflush) if $handle
73 };
74  
75 0 ▶method say ( $say, %opt ) {
Subroutine say: not called CC=3 SCAR=24.8
Pod undocumented
76 0 ▶ if ( refstr($say) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (refstr($say) eq 'ARRAY') { } 0 0 0
77 0 $handle->say($_) for @$say;
78 }
79 else {
80 0 $handle->say( $handle, $say );
81 }
82 1 }
83  
84 0 ▶method refresh (%opt) {
Subroutine refresh: not called CC=11 SCAR=48.8
Pod undocumented
85 $handle = IO::Handle::Common::Handle->new(
86 fd => $opt{fd},
87 mode => $opt{mode}
88 0 ▶ ) unless $handle && blessed($handle) && $handle->opened;
Branch: 1 branch
BranchTrueFalseTotal
unless $handle and builtin::blessed($handle) and $handle->opened 0 0 0
Condition0%0/6
$handle and builtin::blessed($handle) and $handle->opened
!ll&&!rl&&r
000
$handle and builtin::blessed($handle)
!ll&&!rl&&r
000
MC/DC0%0/3
$handle and builtin::blessed($handle) and $handle->opened
$handle builtin::blessed($handle) $handle->opened
Truth table0%0/4
A and B and C
A= $handleB= builtin::blessed($handle)C= $handle->opened
ABCresult
0XX0
10X0
1100
1111
89  
90 0 ▶ if ( $opt{on} && refstr( $opt{on} ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"on"} and refstr($opt{"on"}) eq "CODE") 0 0 0
Condition0%0/3
$opt{"on"} and refstr($opt{"on"}) eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$opt{"on"} and refstr($opt{"on"}) eq "CODE"
$opt{"on"} refstr($opt{"on"}) eq "CODE"
Truth table0%0/3
A and B
A= $opt{"on"}B= refstr($opt{"on"}) eq "CODE"
ABresult
0X0
100
111
91 0 ( delete $opt{on} )->( $handle, %opt );
92 }
93  
94 0 ▶ if ( $opt{method} && $handle->can( $opt{method} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"method"} and $handle->can($opt{"method"})) 0 0 0
Condition0%0/3
$opt{"method"} and $handle->can($opt{"method"})
!ll&&!rl&&r
000
MC/DC0%0/2
$opt{"method"} and $handle->can($opt{"method"})
$opt{"method"} $handle->can($opt{"method"})
Truth table0%0/3
A and B
A= $opt{"method"}B= $handle->can($opt{"method"})
ABresult
0X0
100
111
95 0 my $package = blessed($handle);
96 0 my $meth = delete $opt{method};
97 die "Named parameter 'callarg' must be an ARRAY"
98 if $opt{callarg}
99 0 ▶ && refstr( $opt{callarg} ) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"callarg"} and refstr($opt{"callarg"}) ne "ARRAY" 0 0 0
Condition0%0/3
$opt{"callarg"} and refstr($opt{"callarg"}) ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$opt{"callarg"} and refstr($opt{"callarg"}) ne "ARRAY"
$opt{"callarg"} refstr($opt{"callarg"}) ne "ARRAY"
Truth table0%0/3
A and B
A= $opt{"callarg"}B= refstr($opt{"callarg"}) ne "ARRAY"
ABresult
0X0
100
111
100 0 $handle->$meth( $opt{callarg}->@* );
101 }
102  
103 $handle->close
104 0 ▶ unless any { $_ } ( @opt{qw'keep_open noclose interactive'} );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $_; } , @opt{"keep_open", "noclose", "interactive"}) 0 0 0
105  
106 0 $self;
107 1 }
108  
109 0 ▶method autoflush ( $enable = 1 ) {
Subroutine autoflush: not called CC=3 SCAR=24.8
Pod undocumented
110 0 ▶ $autoflush = $enable if $autoflush != $enable;
Branch: 1 branch
BranchTrueFalseTotal
if $autoflush != $enable 0 0 0
111 0 $handle->autoflush($autoflush);
112 1 }
113  
114 method default_layer : common {
115 $DEFAULT_LAYER;
116 }
↑ Summary Common.pm »