lib/File/DataClass/IO.pm

filter: Statementstmt 97.4% 786 / 809 (2 uncoverable) Branchbran 82.7% 334 / 406 (4 uncoverable) Conditioncond 79.9% 180 / 229 (3 uncoverable) MC/DCmcdc 60.9% 75 / 133 (6 uncoverable) Subroutinesub 98.8% 169 / 171 Podpod 100% 105 / 105 totaltotal 89.6% 1649 / 1853 (15 uncoverable) CC 290 SCAR 15.7
CC
290
Cov
91%
__ANON__
18.8
__ANON__
17.1
open
13.7
CRAP 4.8
« lib/File/DataClass/Functions.pm ↑ Summary lib/File/DataClass/Cache.pm »
1 package File::DataClass::IO;
2  
3 7 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 7 ▶use Cwd qw( );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Fcntl qw( :flock :seek );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use File::Basename ( );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use File::Copy ( );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use File::DataClass::Constants qw( EXCEPTION_CLASS FALSE LOCK_BLOCKING
Subroutine BEGIN: called CC=1 SCAR=0.0
11 LOCK_NONBLOCKING NO_UMASK_STACK NUL
12 7 PERMS STAT_FIELDS TILDE TRUE );
13 7 ▶use File::DataClass::Functions qw( ensure_class_loaded first_char is_arrayref
Subroutine BEGIN: called CC=1 SCAR=0.0
14 is_coderef is_hashref is_member is_mswin
15 7 is_ntfs thread_id throw );
16 7 ▶use File::Spec ( );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶use File::Spec::Functions qw( curdir updir );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶use IO::Dir;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 7 ▶use List::Util qw( first );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 7 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 7 ▶use Sub::Install qw( install_sub );
Subroutine BEGIN: called CC=1 SCAR=0.0
24 7 ▶use Type::Utils qw( enum );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 7 ▶use Unexpected::Functions qw( InvocantUndefined PathNotFound Unspecified );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 7 ▶use Unexpected::Types qw( ArrayRef Bool CodeRef Int Maybe Object
Subroutine BEGIN: called CC=1 SCAR=0.0
27 7 PositiveInt RegexpRef SimpleStr Str );
28 7 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 7 ▶use namespace::clean -except => [ 'meta' ];
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1019 ▶use overload '""' => sub { $_[ 0 ]->as_string },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
32 798 ▶ 'bool' => sub { $_[ 0 ]->as_boolean },
Subroutine __ANON__: called CC=1 SCAR=0.0
33 7 'fallback' => TRUE;
34  
35 7 my $IO_LOCK = enum 'IO_Lock' => [ FALSE, LOCK_BLOCKING, LOCK_NONBLOCKING ];
36 7 my $IO_MODE = enum 'IO_Mode' => [ qw( a a+ r r+ w w+ ) ];
37 7 my $IO_TYPE = enum 'IO_Type' => [ qw( dir file ) ];
38  
39 # Attribute constructors
40 0 ▶my $_build_dir_pattern = sub {
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine _build__dir_pattern: called CC=1 SCAR=1.2
41 0 my $cd = curdir; my $ud = updir; qr{ \A (?: \Q${cd}\E | \Q${ud}\E ) \z }mx;
42 7 };
43  
44 505 ▶my $_catfile = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
45 505 ▶ return File::Spec->catfile( map { defined( $_ ) ? $_ : NUL } @_ );
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1037 0 1037
46 7 };
47  
48 4 ▶my $_expand_tilde = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
49 4 (my $path = $_[ 0 ]) =~ m{ \A ([~] [^/\\]*) .* }mx;
50  
51 4 my ($dir) = glob( $1 ); $path =~ s{ \A ([~] [^/\\]*) }{$dir}mx;
52  
53 4 return $path;
54 7 };
55  
56 647 ▶my $_coerce_name = sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
57 647 my $name = shift;
58  
59 647 ▶ not defined $name and return;
Branch: 1 branch
BranchTrueFalseTotal
defined $name or return 646 1 647
60 646 ▶ is_coderef $name and $name = $name->();
Branch: 1 branch
BranchTrueFalseTotal
&is_coderef($name) and $name = &$name() 1 645 646
61 646 ▶ blessed $name and $name = "${name}";
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($name) and $name = "$name" 3 643 646
62 646 ▶ is_arrayref $name and $name = $_catfile->( @{ $name } );
Branch: 1 branch
BranchTrueFalseTotal
&is_arrayref($name) and $name = &$_catfile(@{$name;}) 394 252 646
63 646 ▶ first_char $name eq TILDE and $name = $_expand_tilde->( $name );
Branch: 1 branch
BranchTrueFalseTotal
&first_char($name) eq "~" and $name = &$_expand_tilde($name) 4 642 646
64 646 ▶ curdir eq $name and $name = Cwd::getcwd();
Branch: 1 branch
BranchTrueFalseTotal
"." eq $name and $name = Cwd::getcwd() 7 639 646
65 646 ▶ CORE::length $name > 1 and $name =~ s{ [/\\] \z }{}mx;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $name > 1 and $name =~ s( [/\\] \z )[]mx 600 46 646
66 646 return $name;
67 7 };
68  
69 # Public attributes
70 7 has 'autoclose' => is => 'lazy', isa => Bool, default => TRUE ;
71 7 has 'have_lock' => is => 'rwp', isa => Bool, default => FALSE ;
72 7 has 'io_handle' => is => 'rwp', isa => Maybe[Object] ;
73 7 has 'is_open' => is => 'rwp', isa => Bool, default => FALSE ;
74 7 has 'mode' => is => 'rwp', isa => $IO_MODE | PositiveInt,
75 default => 'r' ;
76 7 has 'name' => is => 'rwp', isa => SimpleStr, default => NUL,
77 coerce => $_coerce_name, lazy => TRUE ;
78 7 has '_perms' => is => 'rwp', isa => PositiveInt, default => PERMS,
79 init_arg => 'perms' ;
80 7 has 'reverse' => is => 'lazy', isa => Bool, default => FALSE ;
81 7 has 'sort' => is => 'lazy', isa => Bool, default => TRUE ;
82 7 has 'type' => is => 'rwp', isa => Maybe[$IO_TYPE] ;
83  
84 # Private attributes
85 7 has '_assert' => is => 'rw', isa => Bool, default => FALSE ;
86 7 has '_atomic' => is => 'rw', isa => Bool, default => FALSE ;
87 7 has '_atomic_infix' => is => 'rw', isa => SimpleStr, default => 'B_*' ;
88 7 has '_backwards' => is => 'rw', isa => Bool, default => FALSE ;
89 7 has '_block_size' => is => 'rw', isa => PositiveInt, default => 1024 ;
90 7 has '_chomp' => is => 'rw', isa => Bool, default => FALSE ;
91 7 has '_deep' => is => 'rw', isa => Bool, default => FALSE ;
92 7 has '_dir_pattern' => is => 'lazy', isa => RegexpRef,
93 builder => $_build_dir_pattern ;
94 7 has '_filter' => is => 'rw', isa => Maybe[CodeRef] ;
95 has '_layers' => is => 'ro', isa => ArrayRef[SimpleStr],
96 588 ▶ builder => sub { [] } ;
Subroutine _build__layers: called CC=1 SCAR=0.0
97 7 has '_lock' => is => 'rw', isa => $IO_LOCK, default => FALSE ;
98 7 has '_no_follow' => is => 'rw', isa => Bool, default => FALSE ;
99 7 has '_separator' => is => 'rw', isa => Str, default => $RS ;
100 has '_umask' => is => 'ro', isa => ArrayRef[Int],
101 588 ▶ builder => sub { [] } ;
Subroutine _build__umask: called CC=1 SCAR=0.0
102  
103 # Construction
104 7 my @ARG_NAMES = qw( name mode perms );
105  
106 3 ▶my $_clone_one_of_us = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
107 3 my ($self, $params) = @_;
108  
109 3 $self->autoclose; $self->reverse; $self->sort; # Force evaluation
110  
111 3 ▶ my $clone = { %{ $self }, %{ $params // {} } };
Condition100%2/2
$params // {}
l!l
12
MC/DC100%1/1
$params // {}
$params
Truth table100%2/2
A
A= $params
Aresult
11
00
112 3 ▶ my $perms = delete $clone->{_perms}; $clone->{perms} //= $perms;
Condition66%2/3
$clone->{"perms"} //= $perms
l!l&&r!l&&!r
120
MC/DC0%0/2
$clone->{"perms"} //= $perms
$clone->{"perms"} $perms
Truth table66%2/3
A //= B
A= $clone->{"perms"}B= $perms
ABresult
1X1
011
000
113  
114 3 return $clone;
115 7 };
116  
117 358 ▶my $_constructor = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
118 358 my $self = shift; return (blessed $self)->new( @_ );
119 7 };
120  
121 219 ▶my $_inline_args = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
122 219 my $n = shift; return (map { $ARG_NAMES[ $_ ] => $_[ $_ ] } 0 .. $n - 1);
123 7 };
124  
125 570 ▶my $_is_one_of_us = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
126 570 ▶ return (blessed $_[ 0 ]) && $_[ 0 ]->isa( __PACKAGE__ );
Condition100%3/3
builtin::blessed($_[0]) && $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
56433
MC/DC100%2/2
builtin::blessed($_[0]) && $_[0]->isa(__PACKAGE__)
builtin::blessed($_[0]) $_[0]->isa(__PACKAGE__)
Truth table100%3/3
A && B
A= builtin::blessed($_[0])B= $_[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
127 7 };
128  
129 591 ▶sub BUILDARGS { # Differentiate constructor method signatures
Subroutine BUILDARGS: called CC=9 SCAR=22.0
Pod documented
130 591 ▶ my $class = shift; my $n = 0; $n++ while (defined $_[ $n ]);
Branch: 1 branch
BranchTrueFalseTotal
defined $_[$n] and do { ++$n } 936 591 1527
131  
132 return ( $n == 0 ) ? { io_handle => IO::Handle->new }
133 : $_is_one_of_us->( $_[ 0 ] ) ? $_clone_one_of_us->( @_ )
134 2 ▶ : is_hashref( $_[ 0 ] ) ? { %{ $_[ 0 ] } }
Branch: 2 branches
BranchTrueFalseTotal
$n == 1 ? : 210 355 565
&is_hashref($_[1]) ? : 345 10 355
135 : ( $n == 1 ) ? { $_inline_args->( 1, @_ ) }
136 591 ▶ : is_hashref( $_[ 1 ] ) ? { name => $_[ 0 ], %{ $_[ 1 ] } }
Branch: 5 branches
BranchTrueFalseTotal
$n == 0 ? : 21 570 591
&$_is_one_of_us($_[0]) ? : 3 567 570
&is_hashref($_[0]) ? : 2 565 567
$n == 2 ? : 1 9 10
$n == 3 ? : 8 1 9
137 : ( $n == 2 ) ? { $_inline_args->( 2, @_ ) }
138 : ( $n == 3 ) ? { $_inline_args->( 3, @_ ) }
139 : { @_ };
140 }
141  
142 590 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod documented
143 590 my $self = shift; my $handle = $self->io_handle;
144  
145 590 ▶ not $self->name and $handle and $self->_set_is_open( $handle->opened );
Branch: 1 branch
BranchTrueFalseTotal
not $self->name and $handle and $self->_set_is_open($handle->opened) 21 569 590
Condition100%3/3
not $self->name and $handle
!ll&&!rl&&r
568121
MC/DC100%2/2
not $self->name and $handle
not $self->name $handle
Truth table100%3/3
not(A) and B
A= not $self->nameB= $handle
ABresult
0X0
100
111
146  
147 590 return;
148 }
149  
150 2 ▶sub clone {
Subroutine clone: called CC=2 SCAR=6.9
Pod documented
151 2 ▶ my ($self, @args) = @_; blessed $self or throw 'Clone is an object method';
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) or &throw("Clone is an object method") 1 1 2
152  
153 1 return $self->$_constructor( $self, @args );
154 }
155  
156 589 ▶sub DEMOLISH {
Subroutine DEMOLISH: called CC=3 SCAR=11.0
Pod documented
157 589 my ($self, $gd) = @_;
158  
159 589 ▶ $gd and return; # uncoverable branch true
Branch: 1 branch
BranchTrueFalseTotal
$gd and return 0 589 589
160 589 ▶ $self->_atomic ? $self->delete : $self->close;
Branch: 1 branch
BranchTrueFalseTotal
$self->_atomic ? : 19 570 589
161 589 return;
162 }
163  
164 14 ▶sub import {
Subroutine import: called CC=3 SCAR=11.0
165 14 my ($class, @wanted) = @_; my $package = caller;
166  
167 (not defined $wanted[ 0 ] or $wanted[ 0 ] eq 'io')
168 233 ▶ and install_sub { into => $package, as => 'io', code => sub (;@) {
Subroutine __ANON__: called CC=1 SCAR=0.0
169 233 return $class->new( @_ );
170 14 ▶ } };
Branch: 1 branch
BranchTrueFalseTotal
!defined($wanted[0]) || $wanted[0] eq "io" and install_sub({"into", $package, "as", "io", "code", sub (;@) { return $class->new(@_); } }) 13 1 14
Condition100%3/3
not defined $wanted[0] or $wanted[0] eq "io"
l!l&&r!l&&!r
761
MC/DC100%2/2
not defined $wanted[0] or $wanted[0] eq "io"
not defined $wanted[0] $wanted[0] eq "io"
Truth table100%3/3
not(A) or B
A= not defined $wanted[0]B= $wanted[0] eq "io"
ABresult
1X1
011
000
171  
172 14 return;
173 }
174  
175 # Private functions
176 205 ▶my $_should_include_path = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
177 205 ▶ return (not defined $_[ 0 ] or (map { $_[ 0 ]->() } ($_[ 1 ]))[ 0 ]);
Condition100%3/3
!defined($_[0]) || (map {$_[0]->();} $_[1])[0]
l!l&&r!l&&!r
187513
MC/DC100%2/2
!defined($_[0]) || (map {$_[0]->();} $_[1])[0]
!defined($_[0]) (map {$_[0]->();} $_[1])[0]
Truth table100%3/3
not(A) || B
A= !defined($_[0])B= (map {$_[0]->();} $_[1])[0]
ABresult
1X1
011
000
178 7 };
179  
180 # Private methods
181 59 ▶my $_all_file_contents = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
182 59 ▶ my $self = shift; $self->is_open or $self->assert_open;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_open or $self->assert_open 1 58 59
183  
184 57 local $RS = undef; my $content = $self->io_handle->getline;
185  
186 57 ▶ $self->error_check; $self->autoclose and $self->close;
Branch: 1 branch
BranchTrueFalseTotal
$self->autoclose and $self->close 56 1 57
187  
188 57 return $content;
189 7 };
190  
191 7 ▶my $_find; $_find = sub {
Subroutine __ANON__: called CC=17 SCAR=28.4
192 104 my ($self, $files, $dirs, $level) = @_; my (@all, $io);
193  
194 104 my $filter = $self->_filter; my $follow = not $self->_no_follow;
195  
196 104 ▶ defined $level or $level = $self->_deep ? 0 : 1;
Branch: 2 branches
BranchTrueFalseTotal
defined $level or $level = $self->_deep ? 0 : 1 94 10 104
$self->_deep ? : 7 3 10
197  
198 104 ▶ while ($io = $self->next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($io = $self->next) 240 104 344
199 240 ▶ my $is_dir = $io->is_dir; defined $is_dir or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $is_dir or next 240 0 240
200  
201 240 ▶ (($files and not $is_dir) or ($dirs and $is_dir))
Branch: 1 branch
BranchTrueFalseTotal
$files && !$is_dir || $dirs && $is_dir and &$_should_include_path($filter, $io) and push @all, $io 156 84 240
Condition100%12/12
$files && !$is_dir || $dirs && $is_dir and &$_should_include_path($filter, $io)
!ll&&!rl&&r
795156
$files and not $is_dir or $dirs and $is_dir
l!l&&r!l&&!r
936879
$files and not $is_dir
!ll&&!rl&&r
876093
$dirs and $is_dir
!ll&&!rl&&r
275268
MC/DC100%5/5
$files && !$is_dir || $dirs && $is_dir and &$_should_include_path($filter, $io)
$files not $is_dir $dirs $is_dir &$_should_include_path($filter, $io)
Truth table60%6/10
A and not(B) or C and D and E
A= $filesB= not $is_dirC= $dirsD= $is_dirE= &$_should_include_path($filter, $io)
ABCDEresult
0X0XX0
0X10X0
100XX0
1010X0
11XX00
0X1100
101100
11XX11
0X1111
101111
202 and $_should_include_path->( $filter, $io ) and push @all, $io;
203  
204 240 ▶ $is_dir and ($follow or not $io->is_link) and $level != 1
Branch: 2 branches
BranchTrueFalseTotal
$is_dir and $follow || !$io->is_link and $level != 1 and push @all, $io->$_find($files, $dirs, $level ? $level - 1 : 0) 76 164 240
$level ? : 39 37 76
Condition100%9/9
$is_dir and $follow || !$io->is_link and $level != 1
!ll&&!rl&&r
1461876
$is_dir and $follow || !$io->is_link
!ll&&!rl&&r
145194
$follow or not $io->is_link
l!l&&r!l&&!r
9311
MC/DC100%4/4
$is_dir and $follow || !$io->is_link and $level != 1
$is_dir $follow not $io->is_link $level != 1
Truth table83%5/6
A and B or not(C) and D
A= $is_dirB= $followC= not $io->is_linkD= $level != 1
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
205 and push @all, $io->$_find( $files, $dirs, $level ? $level - 1 : 0 );
206 }
207  
208 104 ▶ not $self->sort and return @all;
Branch: 1 branch
BranchTrueFalseTotal
$self->sort or return @all 104 0 104
209  
210 0 return $self->reverse ? sort { $b->name cmp $a->name } @all
211 104 ▶ : sort { $a->name cmp $b->name } @all;
Branch: 1 branch
BranchTrueFalseTotal
$self->reverse ? : 0 104 104
212 7 };
213  
214 111 ▶my $_get_atomic_path = sub {
Subroutine __ANON__: called CC=5 SCAR=16.3
215 111 my $self = shift; my $path = $self->filepath; my $file;
216  
217 111 my $infix = $self->_atomic_infix; my $tid = thread_id;
218  
219 111 ▶ $infix =~ m{ \%P }mx and $infix =~ s{ \%P }{$PID}gmx;
Branch: 1 branch
BranchTrueFalseTotal
$infix =~ / \%P /mx and $infix =~ s/ \%P /$File::DataClass::IO::PID/gmx 0 111 111
220 111 ▶ $infix =~ m{ \%T }mx and $infix =~ s{ \%T }{$tid}gmx;
Branch: 1 branch
BranchTrueFalseTotal
$infix =~ / \%T /mx and $infix =~ s/ \%T /$tid/gmx 0 111 111
221  
222 111 ▶ if ($infix =~ m{ \* }mx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($infix =~ / \* /mx) { } 108 3 111
223 108 my $name = $self->filename; ($file = $infix) =~ s{ \* }{$name}mx;
224 }
225 3 else { $file = $self->filename.$infix }
226  
227 111 ▶ return $path ? $_catfile->( $path, $file ) : $file;
Branch: 1 branch
BranchTrueFalseTotal
$path ? : 111 0 111
228 7 };
229  
230 412 ▶my $_init = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
231 412 my ($self, $type, $name) = @_;
232  
233 412 $self->_set_io_handle( undef );
234 412 $self->_set_is_open ( FALSE );
235 412 ▶ $self->_set_name ( $name ) if ($name);
Branch: 1 branch
BranchTrueFalseTotal
if $name 2 410 412
236 412 $self->_set_mode ( 'r' );
237 412 $self->_set_type ( $type );
238  
239 412 return $self;
240 7 };
241  
242 7 ▶my $_mkdir_perms = sub { # Take file perms and add execute if read is true
Subroutine __ANON__: called CC=2 SCAR=8.1
243 7 ▶ my $perms = $_[ 1 ] || $_[ 0 ]->_perms;
Condition33%1/3
$_[1] || $_[0]->_perms
l!l&&r!l&&!r
070
MC/DC0%0/2
$_[1] || $_[0]->_perms
$_[1] $_[0]->_perms
Truth table33%1/3
A || B
A= $_[1]B= $_[0]->_perms
ABresult
1X1
011
000
244  
245 7 return (($perms & oct '0444') >> 2) | $perms;
246 7 };
247  
248 13 ▶my $_push_layer = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
249 13 ▶ my ($self, $layer) = @_; $layer //= NUL;
Condition50%1/2
$layer //= ""
l!l
130
MC/DC0%0/1
$layer //= ""
$layer
Truth table50%1/2
A
A= $layer
Aresult
11
00
250  
251 13 ▶ is_member $layer, $self->_layers and return FALSE;
Branch: 1 branch
BranchTrueFalseTotal
&is_member($layer, $self->_layers) and return 0 5 8 13
252 8 push @{ $self->_layers }, $layer;
253 8 return TRUE;
254 7 };
255  
256 19 ▶my $_sane_binmode = sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
257 19 my ($self, $layer) = @_;
258  
259 19 ▶ blessed $self->io_handle eq 'File::ReadBackwards' and return;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self->io_handle) eq "File::ReadBackwards" and return 0 19 19
260  
261 19 ▶ return $layer ? CORE::binmode( $self->io_handle, $layer )
Branch: 1 branch
BranchTrueFalseTotal
$layer ? : 18 1 19
262 : CORE::binmode( $self->io_handle );
263 7 };
264  
265 14 ▶my $_throw = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
266 14 my $self = shift; eval { $self->unlock }; throw @_;
267 7 };
268  
269 148 ▶my $_umask_pop = sub {
Subroutine __ANON__: called CC=3 SCAR=11.6
270 148 my $self = shift; my $perms = $self->_umask->[ -1 ];
271  
272 148 ▶ (defined $perms and $perms != NO_UMASK_STACK) or return umask;
Branch: 1 branch
BranchTrueFalseTotal
defined $perms and $perms != -1 or return umask 148 0 148
Condition33%1/3
defined $perms and $perms != -1
!ll&&!rl&&r
00148
MC/DC0%0/2
defined $perms and $perms != -1
defined $perms $perms != -1
Truth table33%1/3
A and B
A= defined $permsB= $perms != -1
ABresult
0X0
100
111
273  
274 148 umask pop @{ $self->_umask };
275 148 return $perms;
276 7 };
277  
278 149 ▶my $_umask_push = sub {
Subroutine __ANON__: called CC=4 SCAR=14.6
279 149 ▶ my ($self, $perms) = @_; $perms or return umask;
Branch: 1 branch
BranchTrueFalseTotal
$perms or return umask 149 0 149
280  
281 149 my $first = $self->_umask->[ 0 ];
282  
283 149 ▶ defined $first and $first == NO_UMASK_STACK and return umask;
Branch: 1 branch
BranchTrueFalseTotal
defined $first and $first == -1 and return umask 0 149 149
Condition33%1/3
defined $first and $first == -1
!ll&&!rl&&r
14900
MC/DC0%0/2
defined $first and $first == -1
defined $first $first == -1
Truth table33%1/3
A and B
A= defined $firstB= $first == -1
ABresult
0X0
100
111
284  
285 149 $perms ^= oct '0777'; push @{ $self->_umask }, umask $perms;
286  
287 149 return $perms;
288 7 };
289  
290 272 ▶my $_untainted_perms = sub {
Subroutine __ANON__: called CC=5 SCAR=16.6
291 272 ▶ my $self = shift; $self->exists or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->exists or return 243 29 272
292 243 ▶ my $stat = $self->stat // {};
Condition50%1/2
$self->stat // {}
l!l
2430
MC/DC0%0/1
$self->stat // {}
$self->stat
Truth table50%1/2
A
A= $self->stat
Aresult
11
00
293 243 ▶ my $mode = $stat->{mode} // NUL;
Condition50%1/2
$stat->{"mode"} // ""
l!l
2430
MC/DC0%0/1
$stat->{"mode"} // ""
$stat->{"mode"}
Truth table50%1/2
A
A= $stat->{"mode"}
Aresult
11
00
294 243 ▶ my $perms = $mode =~ m{ \A (\d+) \z }mx ? $1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$mode =~ / \A (\d+) \z /mx ? : 243 0 243
295  
296 243 return $perms & oct '07777';
297 7 };
298  
299 741 ▶my $_assert_open_backwards = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
300 741 ▶ my ($self, @args) = @_; $self->is_open and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_open and return 736 5 741
301  
302 5 ensure_class_loaded 'File::ReadBackwards';
303  
304 5 ▶ $self->_set_io_handle( File::ReadBackwards->new( $self->name, @args ) )
Branch: 1 branch
BranchTrueFalseTotal
$self->_set_io_handle("File::ReadBackwards"->new($self->name, @args)) or $self->$_throw("File [_1] cannot open backwards: [_2]", [$self->name, $File::DataClass::IO::OS_ERROR]) 4 1 5
305 or $self->$_throw( 'File [_1] cannot open backwards: [_2]',
306 [ $self->name, $OS_ERROR ] );
307 4 $self->_set_is_open( TRUE );
308 4 $self->_set_mode( 'r' );
309 4 $self->set_lock;
310 4 $self->set_binmode;
311 4 return;
312 7 };
313  
314 379 ▶my $_init_type_from_fs = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
315 379 my $self = shift;
316  
317 379 ▶ CORE::length $self->name or $self->$_throw( Unspecified, [ 'path name' ] );
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $self->name or $self->$_throw(Unspecified(), ["path name"]) 378 1 379
318  
319 378 ▶ return -f $self->name ? $self->file : -d _ ? $self->dir : undef;
Branch: 2 branches
BranchTrueFalseTotal
-f $self->name ? : 210 168 378
-d _ ? : 145 23 168
320 7 };
321  
322 270 ▶my $_open_args = sub {
Subroutine __ANON__: called CC=6 SCAR=18.2
323 270 my ($self, $mode, $perms) = @_;
324  
325 270 ▶ CORE::length $self->name or $self->$_throw( Unspecified, [ 'path name' ] );
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $self->name or $self->$_throw(Unspecified(), ["path name"]) 270 0 270
326  
327 270 ▶ my $pathname = $self->_atomic && !$self->is_reading( $mode )
Branch: 1 branch
BranchTrueFalseTotal
$self->_atomic && !$self->is_reading($mode) ? : 33 237 270
Condition100%3/3
$self->_atomic and not $self->is_reading($mode)
!ll&&!rl&&r
2132433
MC/DC100%2/2
$self->_atomic and not $self->is_reading($mode)
$self->_atomic not $self->is_reading($mode)
Truth table100%3/3
A and not(B)
A= $self->_atomicB= not $self->is_reading($mode)
ABresult
0X0
100
111
328 ? $self->$_get_atomic_path : $self->name;
329  
330 270 ▶ $perms = $self->$_untainted_perms || $perms || $self->_perms;
Condition66%4/6
$self->$_untainted_perms || $perms || $self->_perms
l!l&&r!l&&!r
241290
$self->$_untainted_perms or $perms
l!l&&r!l&&!r
241029
MC/DC0%0/3
$self->$_untainted_perms || $perms || $self->_perms
$self->$_untainted_perms $perms $self->_perms
Truth table50%2/4
A or B || C
A= $self->$_untainted_permsB= $permsC= $self->_perms
ABCresult
1XX1
01X1
0011
0000
331  
332 270 return ($pathname, $self->_set_mode( $mode ), $self->_set__perms( $perms ));
333 7 };
334  
335 128 ▶my $_open_dir = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
336 128 my ($self, $path) = @_;
337  
338 128 ▶ $self->_assert and $self->assert_dirpath( $path );
Branch: 1 branch
BranchTrueFalseTotal
$self->_assert and $self->assert_dirpath($path) 0 128 128
339 128 ▶ $self->_set_io_handle( IO::Dir->new( $path ) )
Branch: 1 branch
BranchTrueFalseTotal
$self->_set_io_handle("IO::Dir"->new($path)) or $self->$_throw("Directory [_1] cannot open", [$path]) 127 1 128
340 or $self->$_throw( 'Directory [_1] cannot open', [ $path ] );
341 127 $self->_set_is_open( TRUE );
342 127 return $self;
343 7 };
344  
345 142 ▶my $_open_file = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
346 142 my ($self, $path, $mode, $perms) = @_;
347  
348 142 ▶ $self->_assert and $self->assert_filepath; $self->$_umask_push( $perms );
Branch: 1 branch
BranchTrueFalseTotal
$self->_assert and $self->assert_filepath 1 141 142
349  
350 142 ▶ unless ($self->_set_io_handle( IO::File->new( $path, $mode ) )) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_set_io_handle("IO::File"->new($path, $mode))) 2 140 142
351 2 $self->$_umask_pop;
352 2 $self->$_throw( 'File [_1] cannot open', [ $path ] );
353 }
354  
355 140 $self->$_umask_pop;
356 # TODO: Not necessary on normal systems
357 140 ▶ $self->is_writing and CORE::chmod $perms, $path;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_writing and CORE::chmod $perms, $path 63 77 140
358 140 $self->_set_is_open( TRUE );
359 140 $self->set_lock;
360 140 $self->set_binmode;
361 140 return $self;
362 7 };
363  
364 64 ▶my $_print = sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
365 64 my ($self, @args) = @_;
366  
367 64 for (@args) {
368 1534 ▶ print {$self->io_handle} $_
Branch: 1 branch
BranchTrueFalseTotal
print {$self->io_handle;} $_ or $self->$_throw("IO error: [_1]", [$File::DataClass::IO::OS_ERROR]) 1534 0 1534
369 or $self->$_throw( 'IO error: [_1]', [ $OS_ERROR ] );
370 }
371  
372 64 return $self;
373 7 };
374  
375 57 ▶my $_rename_atomic = sub {
Subroutine __ANON__: called CC=6 SCAR=29.3
376 57 ▶ my $self = shift; my $path = $self->$_get_atomic_path; -f $path or return;
Branch: 1 branch
BranchTrueFalseTotal
-f $path or return 32 25 57
377  
378 32 ▶ File::Copy::move( $path, $self->name ) and return;
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::move($path, $self->name) and return 32 0 32
379  
380 0 ▶ is_ntfs or $self->$_throw( 'Path [_1] move to [_2] failed: [_3]',
Branch: 1 branch
BranchTrueFalseTotal
&is_ntfs() or $self->$_throw("Path [_1] move to [_2] failed: [_3]", [$path, $self->name, $File::DataClass::IO::OS_ERROR]) 0 0 0
381 [ $path, $self->name, $OS_ERROR ] );
382  
383 # Try this instead on ntfs
384 0 warn 'NTFS: Path '.$self->name." move failure: ${OS_ERROR}\n";
385 0 eval { unlink $self->name }; my $os_error;
386 0 ▶ File::Copy::copy( $path, $self->name ) or $os_error = $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::copy($path, $self->name) or $os_error = $File::DataClass::IO::OS_ERROR 0 0 0
387 0 eval { unlink $path };
388 0 ▶ $os_error and $self->$_throw( 'Path [_1] copy to [_2] failed: [_3]',
Branch: 1 branch
BranchTrueFalseTotal
$os_error and $self->$_throw("Path [_1] copy to [_2] failed: [_3]", [$path, $self->name, $os_error]) 0 0 0
389 [ $path, $self->name, $os_error ] );
390 0 return;
391 7 };
392  
393 0 ▶my $_close_and_rename = sub { # This creates a race condition
Subroutine __ANON__: not called CC=3 SCAR=23.0
394 # uncoverable subroutine
395 0 my $self = shift; # uncoverable statement
396  
397 0 my $handle; $self->unlock;
398  
399 0 ▶ if ($handle = $self->io_handle) { $handle->close; delete $self->{io_handle} }
Branch: 1 branch
BranchTrueFalseTotal
if ($handle = $self->io_handle) 0 0 0
400  
401 0 ▶ $self->_atomic and $self->$_rename_atomic;
Branch: 1 branch
BranchTrueFalseTotal
$self->_atomic and $self->$_rename_atomic 0 0 0
402  
403 0 return $self;
404 7 };
405  
406 741 ▶my $_getline_backwards = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
407 741 my ($self, @args) = @_; $self->$_assert_open_backwards( @args );
408  
409 740 return $self->io_handle->readline;
410 7 };
411  
412 18 ▶my $_println = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
413 18 ▶ return shift->$_print( map { m{ [\n] \z }mx ? ($_) : ($_, "\n") } @_ );
Branch: 1 branch
BranchTrueFalseTotal
/ [\n] \z /mx ? : 0 744 744
414 7 };
415  
416 274 ▶my $_rename_and_close = sub { # This does not create a race condition
Subroutine __ANON__: called CC=3 SCAR=11.0
417 274 my $self = shift; my $handle;
418  
419 274 ▶ $self->_atomic and $self->$_rename_atomic; $self->unlock;
Branch: 1 branch
BranchTrueFalseTotal
$self->_atomic and $self->$_rename_atomic 57 217 274
420  
421 274 ▶ if ($handle = $self->io_handle) { $handle->close; delete $self->{io_handle} }
Branch: 1 branch
BranchTrueFalseTotal
if ($handle = $self->io_handle) 274 0 274
422  
423 274 return $self;
424 7 };
425  
426 1 ▶my $_getlines_backwards = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
427 1 my $self = shift; my (@lines, $line);
428  
429 1 ▶ while (defined ($line = $self->$_getline_backwards)) { push @lines, $line }
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->$_getline_backwards)) 725 1 726
430  
431 1 return @lines;
432 7 };
433  
434 # Public methods
435 48 ▶sub abs2rel {
Subroutine abs2rel: called CC=1 SCAR=0.0
Pod documented
436 48 return File::Spec->abs2rel( $_[ 0 ]->name, $_[ 1 ] );
437 }
438  
439 4 ▶sub absolute {
Subroutine absolute: called CC=3 SCAR=11.0
Pod documented
440 4 ▶ my ($self, $base) = @_; $base and $base = $_coerce_name->( $base );
Branch: 1 branch
BranchTrueFalseTotal
$base and $base = &$_coerce_name($base) 2 2 4
441  
442 4 ▶ $self->_set_name
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $self->name ? : 3 1 4
443 ( (CORE::length $self->name) ? $self->rel2abs( $base ) : $base );
444 4 return $self;
445 }
446  
447 69 ▶sub all {
Subroutine all: called CC=2 SCAR=6.9
Pod documented
448 69 my ($self, $level) = @_;
449  
450 69 ▶ $self->is_dir and return $self->$_find( TRUE, TRUE, $level );
Branch: 1 branch
BranchTrueFalseTotal
$self->is_dir and return $self->$_find(1, 1, $level) 10 59 69
451  
452 59 return $self->$_all_file_contents;
453 }
454  
455 10 ▶sub all_dirs {
Subroutine all_dirs: called CC=1 SCAR=0.0
Pod documented
456 10 return $_[ 0 ]->$_find( FALSE, TRUE, $_[ 1 ] );
457 }
458  
459 8 ▶sub all_files {
Subroutine all_files: called CC=1 SCAR=0.0
Pod documented
460 8 return $_[ 0 ]->$_find( TRUE, FALSE, $_[ 1 ] );
461 }
462  
463 3 ▶sub append {
Subroutine append: called CC=3 SCAR=11.0
Pod documented
464 3 my ($self, @args) = @_;
465  
466 3 ▶ if ($self->is_open and not $self->is_reading) { $self->seek( 0, SEEK_END ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_open and not $self->is_reading) { } 1 2 3
Condition100%3/3
$self->is_open and not $self->is_reading
!ll&&!rl&&r
111
MC/DC100%2/2
$self->is_open and not $self->is_reading
$self->is_open not $self->is_reading
Truth table100%3/3
A and not(B)
A= $self->is_openB= not $self->is_reading
ABresult
0X0
100
111
467 2 else { $self->assert_open( 'a' ) }
468  
469 3 return $self->$_print( @args );
470 }
471  
472 3 ▶sub appendln {
Subroutine appendln: called CC=3 SCAR=11.0
Pod documented
473 3 my ($self, @args) = @_;
474  
475 3 ▶ if ($self->is_open and not $self->is_reading) { $self->seek( 0, SEEK_END ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_open and not $self->is_reading) { } 1 2 3
Condition100%3/3
$self->is_open and not $self->is_reading
!ll&&!rl&&r
111
MC/DC100%2/2
$self->is_open and not $self->is_reading
$self->is_open not $self->is_reading
Truth table100%3/3
A and not(B)
A= $self->is_openB= not $self->is_reading
ABresult
0X0
100
111
476 2 else { $self->assert_open( 'a' ) }
477  
478 3 return $self->$_println( @args );
479 }
480  
481 798 ▶sub as_boolean {
Subroutine as_boolean: called CC=3 SCAR=11.0
Pod documented
482 798 ▶ return ((CORE::length $_[ 0 ]->name) || $_[ 0 ]->io_handle) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $_[0]->name || $_[0]->io_handle ? : 797 1 798
Condition100%3/3
CORE::length $_[0]->name or $_[0]->io_handle
l!l&&r!l&&!r
79611
MC/DC100%2/2
CORE::length $_[0]->name or $_[0]->io_handle
CORE::length $_[0]->name $_[0]->io_handle
Truth table100%3/3
A or B
A= CORE::length $_[0]->nameB= $_[0]->io_handle
ABresult
1X1
011
000
483 }
484  
485 1019 ▶sub as_string {
Subroutine as_string: called CC=3 SCAR=11.1
Pod documented
486 1019 ▶ my $self = shift; CORE::length $self->name and return $self->name;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $self->name and return $self->name 1018 1 1019
487  
488 1 ▶ return defined $self->io_handle ? $self->io_handle.NUL : NUL;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->io_handle ? : 1 0 1
489 }
490  
491 3 ▶sub assert {
Subroutine assert: called CC=3 SCAR=11.0
Pod documented
492 3 my ($self, $cb) = @_;
493  
494 3 ▶ if ($cb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb) { } 2 1 3
495 2 local $_ = $self;
496 2 ▶ $cb->() or throw 'Path [_1] assertion failure', [ $self->name ];
Branch: 1 branch
BranchTrueFalseTotal
&$cb() or &throw("Path [_1] assertion failure", [$self->name]) 1 1 2
497 }
498 1 else { $self->_assert( TRUE ) }
499  
500 2 return $self;
501 }
502  
503 8 ▶sub assert_dirpath {
Subroutine assert_dirpath: called CC=5 SCAR=16.2
Pod documented
504 8 my ($self, $dir_name) = @_;
505  
506 8 ▶ $dir_name or return; -d $dir_name and return $dir_name;
Branch: 2 branches
BranchTrueFalseTotal
$dir_name or return 5 3 8
-d $dir_name and return $dir_name 1 4 5
507  
508 4 my $perms = $self->$_mkdir_perms; $self->$_umask_push( oct '07777' );
509  
510 4 ▶ unless (CORE::mkdir( $dir_name, $perms )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (CORE::mkdir $dir_name, $perms) 2 2 4
511 2 ensure_class_loaded 'File::Path';
512 2 File::Path::make_path( $dir_name, { mode => $perms } );
513 }
514  
515 3 $self->$_umask_pop;
516  
517 # uncoverable branch true
518 3 ▶ -d $dir_name or $self->$_throw( 'Path [_1] cannot create: [_2]',
Branch: 1 branch
BranchTrueFalseTotal
-d $dir_name or $self->$_throw("Path [_1] cannot create: [_2]", [$dir_name, $File::DataClass::IO::OS_ERROR]) 3 0 3
519 [ $dir_name, $OS_ERROR ] );
520 3 return $dir_name;
521 }
522  
523 7 ▶sub assert_filepath {
Subroutine assert_filepath: called CC=2 SCAR=6.9
Pod documented
524 7 my $self = shift; my $dir;
525  
526 7 ▶ CORE::length $self->name or $self->$_throw( Unspecified, [ 'path name' ] );
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $self->name or $self->$_throw(Unspecified(), ["path name"]) 6 1 7
527  
528 6 (undef, $dir) = File::Spec->splitpath( $self->name );
529  
530 6 $self->assert_dirpath( $dir );
531 6 return $self;
532 }
533  
534 665 ▶sub assert_open {
Subroutine assert_open: called CC=2 SCAR=6.9
Pod documented
535 665 ▶ return $_[ 0 ]->open( $_[ 1 ] // 'r', $_[ 2 ] );
Condition100%2/2
$_[1] // "r"
l!l
89576
MC/DC100%1/1
$_[1] // "r"
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
536 }
537  
538 34 ▶sub atomic {
Subroutine atomic: called CC=1 SCAR=0.0
Pod documented
539 34 $_[ 0 ]->_atomic( TRUE ); return $_[ 0 ];
540 }
541  
542 2 ▶sub atomic_infix {
Subroutine atomic_infix: called CC=2 SCAR=6.9
Pod documented
543 2 ▶ defined $_[ 1 ] and $_[ 0 ]->_atomic_infix( $_[ 1 ] ); return $_[ 0 ];
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] and $_[0]->_atomic_infix($_[1]) 1 1 2
544 }
545  
546 2 ▶sub atomic_suffix {
Subroutine atomic_suffix: called CC=2 SCAR=6.9
Pod documented
547 2 ▶ defined $_[ 1 ] and $_[ 0 ]->_atomic_infix( $_[ 1 ] ); return $_[ 0 ];
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] and $_[0]->_atomic_infix($_[1]) 1 1 2
548 }
549  
550 2 ▶sub backwards {
Subroutine backwards: called CC=1 SCAR=0.0
Pod documented
551 2 $_[ 0 ]->_backwards( TRUE ); return $_[ 0 ];
552 }
553  
554 2 ▶sub basename {
Subroutine basename: called CC=2 SCAR=6.9
Pod documented
555 2 ▶ my ($self, @suffixes) = @_; CORE::length $self->name or return;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $self->name or return 1 1 2
556  
557 1 return File::Basename::basename( $self->name, @suffixes );
558 }
559  
560 3 ▶sub binary {
Subroutine binary: called CC=3 SCAR=11.0
Pod documented
561 3 my $self = shift;
562  
563 3 ▶ $self->$_push_layer( ':raw' ) and $self->is_open and $self->$_sane_binmode;
Branch: 1 branch
BranchTrueFalseTotal
$self->$_push_layer(":raw") and $self->is_open and $self->$_sane_binmode 1 2 3
Condition100%3/3
$self->$_push_layer(":raw") and $self->is_open
!ll&&!rl&&r
111
MC/DC100%2/2
$self->$_push_layer(":raw") and $self->is_open
$self->$_push_layer(":raw") $self->is_open
Truth table100%3/3
A and B
A= $self->$_push_layer(":raw")B= $self->is_open
ABresult
0X0
100
111
564  
565 3 return $self;
566 }
567  
568 7 ▶sub binmode {
Subroutine binmode: called CC=3 SCAR=11.0
Pod documented
569 7 my ($self, $layer) = @_;
570  
571 7 ▶ $self->$_push_layer( $layer )
Branch: 1 branch
BranchTrueFalseTotal
$self->$_push_layer($layer) and $self->is_open and $self->$_sane_binmode($layer) 1 6 7
Condition100%3/3
$self->$_push_layer($layer) and $self->is_open
!ll&&!rl&&r
421
MC/DC100%2/2
$self->$_push_layer($layer) and $self->is_open
$self->$_push_layer($layer) $self->is_open
Truth table100%3/3
A and B
A= $self->$_push_layer($layer)B= $self->is_open
ABresult
0X0
100
111
572 and $self->is_open and $self->$_sane_binmode( $layer );
573  
574 7 return $self;
575 }
576  
577 4 ▶sub block_size {
Subroutine block_size: called CC=2 SCAR=6.9
Pod documented
578 4 ▶ defined $_[ 1 ] and $_[ 0 ]->_block_size( $_[ 1 ] ); return $_[ 0 ];
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] and $_[0]->_block_size($_[1]) 3 1 4
579 }
580  
581 163 ▶sub buffer {
Subroutine buffer: called CC=5 SCAR=16.1
Pod documented
582 163 my $self = shift;
583  
584 163 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 161 163
585 2 ▶ my $buffer_ref = ref $_[ 0 ] ? $_[ 0 ] : \$_[ 0 ];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 1 2
586  
587 2 ▶ defined ${ $buffer_ref } or ${ $buffer_ref } = NUL;
Branch: 1 branch
BranchTrueFalseTotal
defined ${$buffer_ref;} or ${$buffer_ref;} = "" 1 1 2
588 2 $self->{buffer} = $buffer_ref;
589 2 return $self;
590 }
591  
592 161 ▶ exists $self->{buffer} or $self->{buffer} = do { my $x = NUL; \$x };
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"buffer"} or $self->{"buffer"} = do { my $x = ""; \$x } 160 1 161
593  
594 161 return $self->{buffer};
595 }
596  
597 2 ▶sub canonpath {
Subroutine canonpath: called CC=1 SCAR=0.0
Pod documented
598 2 return File::Spec->canonpath( $_[ 0 ]->name );
599 }
600  
601 3 ▶sub catdir {
Subroutine catdir: called CC=1 SCAR=0.0
Pod documented
602 3 my ($self, @args) = @_; return $self->child( @args )->dir;
603 }
604  
605 5 ▶sub catfile {
Subroutine catfile: called CC=1 SCAR=0.0
Pod documented
606 5 my ($self, @args) = @_; return $self->child( @args )->file;
607 }
608  
609 10 ▶sub child {
Subroutine child: called CC=3 SCAR=11.0
Pod documented
610 10 my ($self, @args) = @_;
611  
612 10 ▶ my $params = (is_hashref $args[ -1 ]) ? pop @args : {};
Branch: 1 branch
BranchTrueFalseTotal
&is_hashref($args[-1]) ? : 1 9 10
613 10 ▶ my $args = [ grep { defined and CORE::length } $self->name, @args ];
Condition100%3/3
defined $_ && CORE::length $_
!ll&&!rl&&r
1421
MC/DC100%2/2
defined $_ && CORE::length $_
defined $_ CORE::length $_
Truth table100%3/3
A && B
A= defined $_B= CORE::length $_
ABresult
0X0
100
111
614  
615 10 return $self->$_constructor( $args, $params );
616 }
617  
618 4 ▶sub chmod {
Subroutine chmod: called CC=2 SCAR=6.9
Pod documented
619 4 my ($self, $perms) = @_;
620  
621 4 ▶ $perms //= $self->_perms; # uncoverable condition false
Condition100%2/3
$perms //= $self->_perms
l!l&&r!l&&!r
220
MC/DC100%0/2
$perms //= $self->_perms
$perms $self->_perms
Truth table100%2/3
A //= B
A= $permsB= $self->_perms
ABresult
1X1
011
000
622 4 CORE::chmod $perms, $self->name;
623 4 return $self;
624 }
625  
626 5 ▶sub chomp {
Subroutine chomp: called CC=1 SCAR=0.0
Pod documented
627 5 $_[ 0 ]->_chomp( TRUE ); return $_[ 0 ];
628 }
629  
630 4 ▶sub chown {
Subroutine chown: called CC=4 SCAR=13.9
Pod documented
631 4 my ($self, $uid, $gid) = @_;
632  
633 4 ▶ (defined $uid and defined $gid)
Branch: 1 branch
BranchTrueFalseTotal
defined $uid and defined $gid or $self->$_throw(Unspecified(), ["user or group id"]) 2 2 4
Condition100%3/3
defined $uid and defined $gid
!ll&&!rl&&r
112
MC/DC100%2/2
defined $uid and defined $gid
defined $uid defined $gid
Truth table100%3/3
A and B
A= defined $uidB= defined $gid
ABresult
0X0
100
111
634 or $self->$_throw( Unspecified, [ 'user or group id' ] );
635  
636 2 ▶ 1 == CORE::chown $uid, $gid, $self->name
Branch: 1 branch
BranchTrueFalseTotal
1 == CORE::chown($uid, $gid, $self->name) or $self->$_throw("Path [_1 chown failed to [_2]/[_3]", [$self->name, $uid, $gid]) 1 1 2
637 or $self->$_throw( 'Path [_1 chown failed to [_2]/[_3]',
638 [ $self->name, $uid, $gid ] );
639 1 return $self;
640 }
641  
642 35 ▶sub clear {
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
643 35 ${ $_[ 0 ]->buffer } = NUL; return $_[ 0 ];
644 }
645  
646 890 ▶sub close {
Subroutine close: called CC=3 SCAR=11.0
Pod documented
647 890 ▶ my $self = shift; $self->is_open or return $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_open or return $self 274 616 890
648  
649 274 ▶ if (is_ntfs) { # uncoverable branch true
Branch: 1 branch
BranchTrueFalseTotal
if (&is_ntfs()) { } 0 274 274
650 0 $self->$_close_and_rename; # uncoverable statement
651 274 } else { $self->$_rename_and_close }
652  
653 274 $self->_set_io_handle( undef );
654 274 $self->_set_is_open ( FALSE );
655 274 $self->_set_mode ( 'r' );
656 274 return $self;
657 }
658  
659 4 ▶sub copy {
Subroutine copy: called CC=5 SCAR=16.2
Pod documented
660 4 my ($self, $to) = @_;
661  
662 4 ▶ $to or $self->$_throw( Unspecified, [ 'copy to' ] );
Branch: 1 branch
BranchTrueFalseTotal
$to or $self->$_throw(Unspecified(), ["copy to"]) 4 0 4
663  
664 4 ▶ (blessed $to and $to->isa( __PACKAGE__ ))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($to) and $to->isa(__PACKAGE__) or $to = $self->$_constructor($to) 1 3 4
Condition100%3/3
builtin::blessed($to) and $to->isa(__PACKAGE__)
!ll&&!rl&&r
211
MC/DC100%2/2
builtin::blessed($to) and $to->isa(__PACKAGE__)
builtin::blessed($to) $to->isa(__PACKAGE__)
Truth table100%3/3
A and B
A= builtin::blessed($to)B= $to->isa(__PACKAGE__)
ABresult
0X0
100
111
665 or $to = $self->$_constructor( $to );
666  
667 4 ▶ File::Copy::copy( $self->name, $to->pathname )
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::copy($self->name, $to->pathname) or $self->$_throw("Cannot copy [_1] to [_2]", [$self->name, $to->pathname]) 4 0 4
668 or $self->$_throw( 'Cannot copy [_1] to [_2]',
669 [ $self->name, $to->pathname ] );
670  
671 4 return $to;
672 }
673  
674 1 ▶sub cwd {
Subroutine cwd: called CC=1 SCAR=0.0
Pod documented
675 1 my $self = shift; return $self->$_constructor( Cwd::getcwd(), @_ );
676 }
677  
678 10 ▶sub deep {
Subroutine deep: called CC=1 SCAR=0.0
Pod documented
679 10 $_[ 0 ]->_deep( TRUE ); return $_[ 0 ];
680 }
681  
682 21 ▶sub delete {
Subroutine delete: called CC=3 SCAR=11.0
Pod documented
683 21 my $self = shift; my $path = $self->$_get_atomic_path;
684  
685 21 ▶ $self->_atomic and -f $path and unlink $path;
Branch: 1 branch
BranchTrueFalseTotal
$self->_atomic and -f $path and CORE::unlink $path 1 20 21
Condition100%3/3
$self->_atomic and -f $path
!ll&&!rl&&r
1191
MC/DC100%2/2
$self->_atomic and -f $path
$self->_atomic -f $path
Truth table100%3/3
A and B
A= $self->_atomicB= -f $path
ABresult
0X0
100
111
686  
687 21 return $self->close;
688 }
689  
690 2 ▶sub delete_tmp_files {
Subroutine delete_tmp_files: called CC=4 SCAR=13.9
Pod documented
691 2 ▶ my ($self, $tmplt) = @_; $tmplt //= '%6.6d....';
Condition100%2/2
$tmplt //= "%6.6d...."
l!l
11
MC/DC100%1/1
$tmplt //= "%6.6d...."
$tmplt
Truth table100%2/2
A
A= $tmplt
Aresult
11
00
692  
693 2 my $pat = sprintf $tmplt, $PID;
694  
695 2 ▶ while (my $entry = $self->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $entry = $self->next) 48 2 50
696 48 ▶ $entry->filename =~ m{ \A $pat \z }mx and unlink $entry->pathname;
Branch: 1 branch
BranchTrueFalseTotal
$entry->filename =~ / \A $pat \z /mx and CORE::unlink $entry->pathname 0 48 48
697 }
698  
699 2 return $self->close;
700 }
701  
702 4 ▶sub digest { # Robbed from Path::Tiny
Subroutine digest: called CC=7 SCAR=19.5
Pod documented
703 4 ▶ my ($self, @args) = @_; my $n = 0; $n++ while (defined $args[ $n ]);
Branch: 1 branch
BranchTrueFalseTotal
defined $args[$n] and do { ++$n } 4 4 8
704  
705 my $args = ( $n == 0) ? { algorithm => 'SHA-256' }
706 : (is_hashref $args[ 0 ]) ? { algorithm => 'SHA-256',
707 1 ▶ %{ $args[ 0 ] } }
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 1 1 2
708 : ( $n == 1) ? { algorithm => $args[ 0 ] }
709 : { algorithm => $args[ 0 ],
710 4 ▶ %{ $args[ 1 ] } };
Branch: 2 branches
BranchTrueFalseTotal
$n == 0 ? : 1 3 4
&is_hashref($args[0]) ? : 1 2 3
711  
712 4 ensure_class_loaded 'Digest'; my $digest = Digest->new( $args->{algorithm} );
713  
714 4 ▶ if ($args->{block_size}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'block_size'}) { } 2 2 4
715 2 $self->binmode( ':unix' )->lock->block_size( $args->{block_size} );
716  
717 2 ▶ while ($self->read) { $digest->add( ${ $self->buffer } ); $self->clear; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->read) 20 2 22
718 }
719 2 else { $digest->add( $self->binmode( ':unix' )->lock->all ) }
720  
721 4 return $digest;
722 }
723  
724 172 ▶sub dir {
Subroutine dir: called CC=1 SCAR=0.0
Pod documented
725 172 return shift->$_init( 'dir', @_ );
726 }
727  
728 5 ▶sub dirname {
Subroutine dirname: called CC=2 SCAR=7.6
Pod documented
729 5 ▶ return CORE::length $_[ 0 ]->name ? File::Basename::dirname( $_[ 0 ]->name )
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $_[0]->name ? : 5 0 5
730 : NUL;
731 }
732  
733 4 ▶sub encoding {
Subroutine encoding: called CC=4 SCAR=14.6
Pod documented
734 4 my ($self, $encoding) = @_;
735  
736 4 ▶ $encoding or $self->$_throw( Unspecified, [ 'encoding value' ] );
Branch: 1 branch
BranchTrueFalseTotal
$encoding or $self->$_throw(Unspecified(), ["encoding value"]) 3 1 4
737 3 ▶ $self->$_push_layer( ":encoding($encoding)" )
Branch: 1 branch
BranchTrueFalseTotal
$self->$_push_layer(":encoding($encoding)") and $self->is_open and $self->$_sane_binmode(":encoding($encoding)") 0 3 3
Condition33%1/3
$self->$_push_layer(":encoding($encoding)") and $self->is_open
!ll&&!rl&&r
030
MC/DC0%0/2
$self->$_push_layer(":encoding($encoding)") and $self->is_open
$self->$_push_layer(":encoding($encoding)") $self->is_open
Truth table33%1/3
A and B
A= $self->$_push_layer(":encoding($encoding)")B= $self->is_open
ABresult
0X0
100
111
738 and $self->is_open and $self->$_sane_binmode( ":encoding($encoding)" );
739 3 return $self;
740 }
741  
742 147 ▶sub error_check {
Subroutine error_check: called CC=3 SCAR=12.5
Pod documented
743 147 my $self = shift;
744  
745 147 ▶ $self->io_handle->can( 'error' )
Branch: 1 branch
BranchTrueFalseTotal
$self->io_handle->can("error") and $self->io_handle->error and $self->$_throw("IO error: [_1]", [$File::DataClass::IO::OS_ERROR]) 0 147 147
Condition33%1/3
$self->io_handle->can("error") and $self->io_handle->error
!ll&&!rl&&r
01470
MC/DC0%0/2
$self->io_handle->can("error") and $self->io_handle->error
$self->io_handle->can("error") $self->io_handle->error
Truth table33%1/3
A and B
A= $self->io_handle->can("error")B= $self->io_handle->error
ABresult
0X0
100
111
746 and $self->io_handle->error
747 and $self->$_throw( 'IO error: [_1]', [ $OS_ERROR ] );
748  
749 147 return $self;
750 }
751  
752 388 ▶sub exists {
Subroutine exists: called CC=3 SCAR=11.0
Pod documented
753 388 ▶ return (CORE::length $_[ 0 ]->name && -e $_[ 0 ]->name) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $_[0]->name && -e $_[0]->name ? : 346 42 388
Condition100%3/3
CORE::length $_[0]->name and -e $_[0]->name
!ll&&!rl&&r
141346
MC/DC100%2/2
CORE::length $_[0]->name and -e $_[0]->name
CORE::length $_[0]->name -e $_[0]->name
Truth table100%3/3
A and B
A= CORE::length $_[0]->nameB= -e $_[0]->name
ABresult
0X0
100
111
754 }
755  
756 1 ▶sub fdopen {
Subroutine fdopen: called CC=1 SCAR=0.0
Pod documented
757 1 my ($self, $fd, $mode) = @_;
758  
759 1 $self->io_handle->fdopen( $fd, $mode );
760 1 $self->_set_is_open( $self->io_handle->opened );
761 1 $self->_set_mode( $mode );
762 1 $self->_set_name( NUL );
763 1 $self->_set_type( undef );
764 1 return $self;
765 }
766  
767 240 ▶sub file {
Subroutine file: called CC=1 SCAR=0.0
Pod documented
768 240 return shift->$_init( 'file', @_ );
769 }
770  
771 505 ▶sub filename {
Subroutine filename: called CC=1 SCAR=0.0
Pod documented
772 505 my $self = shift; my $file;
773  
774 505 (undef, undef, $file) = File::Spec->splitpath( $self->name );
775  
776 505 return $file;
777 }
778  
779 111 ▶sub filepath {
Subroutine filepath: called CC=1 SCAR=0.0
Pod documented
780 111 my $self = shift; my ($volume, $dir) = File::Spec->splitpath( $self->name );
781  
782 111 return File::Spec->catpath( $volume, $dir, NUL );
783 }
784  
785 33 ▶sub filter {
Subroutine filter: called CC=2 SCAR=7.2
Pod documented
786 33 ▶ defined $_[ 1 ] and $_[ 0 ]->_filter( $_[ 1 ] ); return $_[ 0 ];
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] and $_[0]->_filter($_[1]) 33 0 33
787 }
788  
789 19 ▶sub getline {
Subroutine getline: called CC=7 SCAR=19.6
Pod documented
790 19 my ($self, $separator) = @_;
791  
792 19 ▶ $self->_backwards and return $self->$_getline_backwards;
Branch: 1 branch
BranchTrueFalseTotal
$self->_backwards and return $self->$_getline_backwards 1 18 19
793  
794 18 my $line; $self->assert_open;
795  
796 18 ▶ { local $RS = $separator // $self->_separator; # uncoverable condition false
Condition100%2/3
$separator // $self->_separator
l!l&&r!l&&!r
1170
MC/DC100%0/2
$separator // $self->_separator
$separator $self->_separator
Truth table100%2/3
A // B
A= $separatorB= $self->_separator
ABresult
1X1
011
000
797 18 $line = $self->io_handle->getline;
798 18 ▶ defined $line and $self->_chomp and CORE::chomp $line;
Branch: 1 branch
BranchTrueFalseTotal
defined $line and $self->_chomp and CORE::chomp $line 0 18 18
Condition66%2/3
defined $line and $self->_chomp
!ll&&!rl&&r
1170
MC/DC0%0/2
defined $line and $self->_chomp
defined $line $self->_chomp
Truth table66%2/3
A and B
A= defined $lineB= $self->_chomp
ABresult
0X0
100
111
799 }
800  
801 18 $self->error_check;
802 18 ▶ defined $line and return $line;
Branch: 1 branch
BranchTrueFalseTotal
defined $line and return $line 17 1 18
803 1 ▶ $self->autoclose and $self->close;
Branch: 1 branch
BranchTrueFalseTotal
$self->autoclose and $self->close 1 0 1
804 1 return;
805 }
806  
807 7 ▶sub getlines {
Subroutine getlines: called CC=7 SCAR=19.5
Pod documented
808 7 my ($self, $separator) = @_;
809  
810 7 ▶ $self->_backwards and return $self->$_getlines_backwards;
Branch: 1 branch
BranchTrueFalseTotal
$self->_backwards and return $self->$_getlines_backwards 1 6 7
811  
812 6 my @lines; $self->assert_open;
813  
814 6 ▶ { local $RS = $separator // $self->_separator; # uncoverable condition false
Condition100%2/3
$separator // $self->_separator
l!l&&r!l&&!r
240
MC/DC100%0/2
$separator // $self->_separator
$separator $self->_separator
Truth table100%2/3
A // B
A= $separatorB= $self->_separator
ABresult
1X1
011
000
815 6 @lines = $self->io_handle->getlines;
816  
817 6 ▶ if ($self->_chomp) { CORE::chomp for @lines }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_chomp) 5 1 6
818 }
819  
820 6 $self->error_check;
821 6 ▶ scalar @lines and return (@lines);
Branch: 1 branch
BranchTrueFalseTotal
scalar @lines and return @lines 5 1 6
822 1 ▶ $self->autoclose and $self->close;
Branch: 1 branch
BranchTrueFalseTotal
$self->autoclose and $self->close 1 0 1
823 1 return ();
824 }
825  
826 2 ▶sub head {
Subroutine head: called CC=5 SCAR=16.2
Pod documented
827 2 ▶ my ($self, $lines) = @_; my @res; $lines //= 10; $self->close;
Condition100%2/2
$lines //= 10
l!l
11
MC/DC100%1/1
$lines //= 10
$lines
Truth table100%2/2
A
A= $lines
Aresult
11
00
828  
829 2 ▶ while ($lines--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines--) 13 2 15
830 13 ▶ defined (my $l = $self->getline) or last; push @res, $l;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $l = $self->getline) or last 13 0 13
831 }
832  
833 2 $self->close;
834 2 ▶ return wantarray ? @res : join NUL, @res;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
835 }
836  
837 4 ▶sub hexdigest {
Subroutine hexdigest: called CC=1 SCAR=0.0
Pod documented
838 4 my ($self, @args) = @_; return $self->digest( @args )->hexdigest;
839 }
840  
841 2 ▶sub is_absolute {
Subroutine is_absolute: called CC=1 SCAR=0.0
Pod documented
842 2 return File::Spec->file_name_is_absolute( $_[ 0 ]->name );
843 }
844  
845 675 ▶sub is_dir {
Subroutine is_dir: called CC=5 SCAR=16.1
Pod documented
846 675 ▶ my $self = shift; CORE::length $self->name or return FALSE;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $self->name or return 0 673 2 675
847  
848 673 ▶ $self->type or $self->$_init_type_from_fs or return FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$self->type or $self->$_init_type_from_fs or return 0 672 1 673
Condition100%3/3
$self->type or $self->$_init_type_from_fs
l!l&&r!l&&!r
3493222
MC/DC100%2/2
$self->type or $self->$_init_type_from_fs
$self->type $self->$_init_type_from_fs
Truth table100%3/3
A or B
A= $self->typeB= $self->$_init_type_from_fs
ABresult
1X1
011
000
849  
850 672 ▶ return $self->type eq 'dir' ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$self->type eq 'dir' ? : 272 400 672
851 }
852  
853 43 ▶sub is_empty {
Subroutine is_empty: called CC=5 SCAR=16.1
Pod documented
854 43 my $self = shift; my $name = $self->name; my $empty;
855  
856 43 ▶ $self->exists or $self->$_throw( PathNotFound, [ $name ] );
Branch: 1 branch
BranchTrueFalseTotal
$self->exists or $self->$_throw(PathNotFound(), [$name]) 40 3 43
857 40 ▶ $self->is_file and return -z $name ? TRUE : FALSE;
Branch: 2 branches
BranchTrueFalseTotal
$self->is_file and return -z $name ? 1 : 0 38 2 40
-z $name ? : 1 37 38
858 2 ▶ $empty = $self->next ? FALSE : TRUE; $self->close;
Branch: 1 branch
BranchTrueFalseTotal
$self->next ? : 0 2 2
859 2 return $empty;
860 }
861  
862 7 *empty = \&is_empty; # Deprecated
863  
864 3 ▶sub is_executable {
Subroutine is_executable: called CC=3 SCAR=11.0
Pod documented
865 3 ▶ return (CORE::length $_[ 0 ]->name) && -x $_[ 0 ]->name ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $_[0]->name && -x $_[0]->name ? : 1 2 3
Condition100%3/3
CORE::length $_[0]->name and -x $_[0]->name
!ll&&!rl&&r
111
MC/DC100%2/2
CORE::length $_[0]->name and -x $_[0]->name
CORE::length $_[0]->name -x $_[0]->name
Truth table100%3/3
A and B
A= CORE::length $_[0]->nameB= -x $_[0]->name
ABresult
0X0
100
111
866 }
867  
868 42 ▶sub is_file {
Subroutine is_file: called CC=5 SCAR=16.1
Pod documented
869 42 ▶ my $self = shift; CORE::length $self->name or return FALSE;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $self->name or return 0 41 1 42
870  
871 41 ▶ $self->type or $self->$_init_type_from_fs or return FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$self->type or $self->$_init_type_from_fs or return 0 40 1 41
Condition100%3/3
$self->type or $self->$_init_type_from_fs
l!l&&r!l&&!r
2894
MC/DC50%1/2
$self->type or $self->$_init_type_from_fs
$self->type $self->$_init_type_from_fs
Truth table66%2/3
A or B
A= $self->typeB= $self->$_init_type_from_fs
ABresult
1X1
011
000
872  
873 40 ▶ return $self->type eq 'file' ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$self->type eq 'file' ? : 38 2 40
874 }
875  
876 461 ▶sub is_link {
Subroutine is_link: called CC=3 SCAR=11.0
Pod documented
877 461 ▶ return (CORE::length $_[ 0 ]->name) && -l $_[ 0 ]->name ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $_[0]->name && -l $_[0]->name ? : 8 453 461
Condition100%3/3
CORE::length $_[0]->name and -l $_[0]->name
!ll&&!rl&&r
14528
MC/DC100%2/2
CORE::length $_[0]->name and -l $_[0]->name
CORE::length $_[0]->name -l $_[0]->name
Truth table100%3/3
A and B
A= CORE::length $_[0]->nameB= -l $_[0]->name
ABresult
0X0
100
111
878 }
879  
880 2 ▶sub is_readable {
Subroutine is_readable: called CC=3 SCAR=11.1
Pod documented
881 2 ▶ return (CORE::length $_[ 0 ]->name) && -r $_[ 0 ]->name ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $_[0]->name && -r $_[0]->name ? : 1 1 2
Condition66%2/3
CORE::length $_[0]->name and -r $_[0]->name
!ll&&!rl&&r
101
MC/DC50%1/2
CORE::length $_[0]->name and -r $_[0]->name
CORE::length $_[0]->name -r $_[0]->name
Truth table66%2/3
A and B
A= CORE::length $_[0]->nameB= -r $_[0]->name
ABresult
0X0
100
111
882 }
883  
884 61 ▶sub is_reading {
Subroutine is_reading: called CC=2 SCAR=7.0
Pod documented
885 61 ▶ my $mode = $_[ 1 ] // $_[ 0 ]->mode; return first { $_ eq $mode } qw( r r+ );
Subroutine __ANON__: called CC=1 SCAR=0.0
Condition66%2/3
$_[1] // $_[0]->mode
l!l&&r!l&&!r
5740
MC/DC0%0/2
$_[1] // $_[0]->mode
$_[1] $_[0]->mode
Truth table66%2/3
A // B
A= $_[1]B= $_[0]->mode
ABresult
1X1
011
000
886 }
887  
888 5 ▶sub is_writable {
Subroutine is_writable: called CC=3 SCAR=11.1
Pod documented
889 5 ▶ return (CORE::length $_[ 0 ]->name) && -w $_[ 0 ]->name ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $_[0]->name && -w $_[0]->name ? : 4 1 5
Condition66%2/3
CORE::length $_[0]->name and -w $_[0]->name
!ll&&!rl&&r
104
MC/DC50%1/2
CORE::length $_[0]->name and -w $_[0]->name
CORE::length $_[0]->name -w $_[0]->name
Truth table66%2/3
A and B
A= CORE::length $_[0]->nameB= -w $_[0]->name
ABresult
0X0
100
111
890 }
891  
892 140 ▶sub is_writing {
Subroutine is_writing: called CC=2 SCAR=7.6
Pod documented
893 140 ▶ my $mode = $_[ 1 ] // $_[ 0 ]->mode;
Condition33%1/3
$_[1] // $_[0]->mode
l!l&&r!l&&!r
01400
MC/DC0%0/2
$_[1] // $_[0]->mode
$_[1] $_[0]->mode
Truth table33%1/3
A // B
A= $_[1]B= $_[0]->mode
ABresult
1X1
011
000
894  
895 140 ▶ return first { $_ eq $mode } qw( a a+ w w+ );
Subroutine __ANON__: called CC=1 SCAR=0.0
896 }
897  
898 5 ▶sub iterator {
Subroutine iterator: called CC=4 SCAR=13.9
Pod documented
899 5 my ($self, $args) = @_;
900  
901 5 ▶ $self->is_dir
Branch: 1 branch
BranchTrueFalseTotal
$self->is_dir or $self->$_throw("Path [_1] is not a directory", [$self->name]) 5 0 5
902 or $self->$_throw( "Path [_1] is not a directory", [ $self->name ] );
903  
904 5 my @dirs = ( $self );
905 5 my $filter = $self->_filter;
906 5 ▶ my $deep = $args->{recurse} // $self->_deep;
Condition66%2/3
$args->{"recurse"} // $self->_deep
l!l&&r!l&&!r
140
MC/DC0%0/2
$args->{"recurse"} // $self->_deep
$args->{"recurse"} $self->_deep
Truth table66%2/3
A // B
A= $args->{"recurse"}B= $self->_deep
ABresult
1X1
011
000
907 5 ▶ my $follow = $args->{follow_symlinks} // not $self->_no_follow;
Condition100%2/2
$args->{"follow_symlinks"} // !$self->_no_follow
l!l
14
MC/DC100%1/1
$args->{"follow_symlinks"} // !$self->_no_follow
$args->{"follow_symlinks"}
Truth table100%2/2
A
A= $args->{"follow_symlinks"}
Aresult
11
00
908  
909 40 ▶ return sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
910 40 ▶ while (@dirs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dirs) 49 4 53
911 49 ▶ while (defined (my $path = $dirs[ 0 ]->next)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $path = $dirs[0]->next)) 44 13 57
912 44 ▶ $deep and $path->is_dir and ($follow or not $path->is_link)
Branch: 1 branch
BranchTrueFalseTotal
$deep and $path->is_dir and $follow || !$path->is_link and unshift @dirs, $path 12 32 44
Condition100%9/9
$deep and $path->is_dir and $follow || !$path->is_link
!ll&&!rl&&r
31112
$deep and $path->is_dir
!ll&&!rl&&r
62513
$follow or not $path->is_link
l!l&&r!l&&!r
1021
MC/DC100%4/4
$deep and $path->is_dir and $follow || !$path->is_link
$deep $path->is_dir $follow not $path->is_link
Truth table100%5/5
A and B and C or not(D)
A= $deepB= $path->is_dirC= $followD= not $path->is_link
ABCDresult
0XXX0
10XX0
11000
111X1
11011
913 and unshift @dirs, $path;
914 44 ▶ $_should_include_path->( $filter, $path ) and return $path;
Branch: 1 branch
BranchTrueFalseTotal
&$_should_include_path($filter, $path) and return $path 36 8 44
915 }
916  
917 13 shift @dirs;
918 }
919  
920 4 return;
921 5 };
922 }
923  
924 53 ▶sub length {
Subroutine length: called CC=1 SCAR=0.0
Pod documented
925 53 return CORE::length ${ $_[ 0 ]->buffer };
926 }
927  
928 70 ▶sub lock {
Subroutine lock: called CC=2 SCAR=6.9
Pod documented
929 70 ▶ $_[ 0 ]->_lock( $_[ 1 ] // LOCK_BLOCKING ); return $_[ 0 ];
Condition100%2/2
$_[1] // 1
l!l
169
MC/DC100%1/1
$_[1] // 1
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
930 }
931  
932 2 ▶sub mkdir {
Subroutine mkdir: called CC=3 SCAR=11.4
Pod documented
933 2 ▶ my ($self, $perms) = @_; $perms ||= $self->$_mkdir_perms;
Condition33%1/3
$perms ||= $self->$_mkdir_perms
l!l&&r!l&&!r
020
MC/DC0%0/2
$perms ||= $self->$_mkdir_perms
$perms $self->$_mkdir_perms
Truth table33%1/3
A ||= B
A= $permsB= $self->$_mkdir_perms
ABresult
1X1
011
000
934  
935 2 $self->$_umask_push( oct '07777' );
936  
937 2 CORE::mkdir( $self->name, $perms );
938  
939 2 $self->$_umask_pop;
940  
941 2 ▶ -d $self->name or $self->$_throw( 'Path [_1] cannot create: [_2]',
Branch: 1 branch
BranchTrueFalseTotal
-d $self->name or $self->$_throw("Path [_1] cannot create: [_2]", [$self->name, $File::DataClass::IO::OS_ERROR]) 2 0 2
942 [ $self->name, $OS_ERROR ] );
943 2 return $self;
944 }
945  
946 1 ▶sub mkpath {
Subroutine mkpath: called CC=3 SCAR=11.3
Pod documented
947 1 ▶ my ($self, $perms) = @_; $perms ||= $self->$_mkdir_perms;
Condition33%1/3
$perms ||= $self->$_mkdir_perms
l!l&&r!l&&!r
010
MC/DC0%0/2
$perms ||= $self->$_mkdir_perms
$perms $self->$_mkdir_perms
Truth table33%1/3
A ||= B
A= $permsB= $self->$_mkdir_perms
ABresult
1X1
011
000
948  
949 1 $self->$_umask_push( oct '07777' ); ensure_class_loaded 'File::Path';
950  
951 1 File::Path::make_path( $self->name, { mode => $perms } );
952  
953 1 $self->$_umask_pop;
954  
955 1 ▶ -d $self->name or $self->$_throw( 'Path [_1] cannot create: [_2]',
Branch: 1 branch
BranchTrueFalseTotal
-d $self->name or $self->$_throw("Path [_1] cannot create: [_2]", [$self->name, $File::DataClass::IO::OS_ERROR]) 1 0 1
956 [ $self->name, $OS_ERROR ] );
957 1 return $self;
958 }
959  
960 3 ▶sub move {
Subroutine move: called CC=5 SCAR=16.2
Pod documented
961 3 my ($self, $to) = @_;
962  
963 3 ▶ $to or $self->$_throw( Unspecified, [ 'move to' ] );
Branch: 1 branch
BranchTrueFalseTotal
$to or $self->$_throw(Unspecified(), ["move to"]) 3 0 3
964  
965 3 ▶ (blessed $to and $to->isa( __PACKAGE__ ))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($to) and $to->isa(__PACKAGE__) or $to = $self->$_constructor($to) 1 2 3
Condition100%3/3
builtin::blessed($to) and $to->isa(__PACKAGE__)
!ll&&!rl&&r
111
MC/DC100%2/2
builtin::blessed($to) and $to->isa(__PACKAGE__)
builtin::blessed($to) $to->isa(__PACKAGE__)
Truth table100%3/3
A and B
A= builtin::blessed($to)B= $to->isa(__PACKAGE__)
ABresult
0X0
100
111
966 or $to = $self->$_constructor( $to );
967  
968 3 ▶ File::Copy::move( $self->name, $to->pathname )
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::move($self->name, $to->pathname) or $self->$_throw("Cannot move [_1] to [_2]", [$self->name, $to->pathname]) 3 0 3
969 or $self->$_throw( 'Cannot move [_1] to [_2]',
970 [ $self->name, $to->pathname ] );
971  
972 3 return $to;
973 }
974  
975 455 ▶sub next {
Subroutine next: called CC=3 SCAR=11.0
Pod documented
976 455 ▶ my $self = shift; defined (my $name = $self->read_dir) or return;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $name = $self->read_dir) or return 333 121 454
977  
978 333 my $io = $self->$_constructor( [ $self->name, $name ], {
979 reverse => $self->reverse, sort => $self->sort } );
980  
981 333 ▶ defined $self->_filter and $io->filter( $self->_filter );
Branch: 1 branch
BranchTrueFalseTotal
defined $self->_filter and $io->filter($self->_filter) 30 303 333
982  
983 333 return $io;
984 }
985  
986 2 ▶sub no_follow {
Subroutine no_follow: called CC=1 SCAR=0.0
Pod documented
987 2 $_[ 0 ]->_no_follow( TRUE ); return $_[ 0 ];
988 }
989  
990 667 ▶sub open {
Subroutine open: called CC=13 SCAR=26.2
Pod documented
991 667 ▶ my ($self, $mode, $perms) = @_; $mode //= $self->mode;
Condition66%2/3
$mode //= $self->mode
l!l&&r!l&&!r
66610
MC/DC0%0/2
$mode //= $self->mode
$mode $self->mode
Truth table66%2/3
A //= B
A= $modeB= $self->mode
ABresult
1X1
011
000
992  
993 667 ▶ $self->is_open
Branch: 1 branch
BranchTrueFalseTotal
$self->is_open and &first_char($mode) eq &first_char(scalar $self->mode) and return $self 403 264 667
Condition100%3/3
$self->is_open and &first_char($mode) eq &first_char(scalar $self->mode)
!ll&&!rl&&r
2586403
MC/DC100%2/2
$self->is_open and &first_char($mode) eq &first_char(scalar $self->mode)
$self->is_open &first_char($mode) eq &first_char(scalar $self->mode)
Truth table100%3/3
A and B
A= $self->is_openB= &first_char($mode) eq &first_char(scalar $self->mode)
ABresult
0X0
100
111
994 and first_char $mode eq first_char $self->mode
995 and return $self;
996 264 ▶ $self->is_open
Branch: 1 branch
BranchTrueFalseTotal
$self->is_open and "r" eq &first_char($mode) and "+" eq substr($self->mode, 1, 1) || "" and $self->seek(0, 0) and return $self 0 264 264
Condition63%7/11
$self->is_open and "r" eq &first_char($mode) and "+" eq substr($self->mode, 1, 1) || "" and $self->seek(0, 0)
!ll&&!rl&&r
26400
$self->is_open and "r" eq &first_char($mode) and "+" eq substr($self->mode, 1, 1) || ""
!ll&&!rl&&r
26040
$self->is_open and "r" eq &first_char($mode)
!ll&&!rl&&r
25824
"+" eq substr($self->mode, 1, 1) or ""
l!l
04
MC/DC0%0/4
$self->is_open and "r" eq &first_char($mode) and "+" eq substr($self->mode, 1, 1) || "" and $self->seek(0, 0)
$self->is_open "r" eq &first_char($mode) "+" eq substr($self->mode, 1, 1) $self->seek(0, 0)
Truth table60%3/5
A and B and C and D
A= $self->is_openB= "r" eq &first_char($mode)C= "+" eq substr($self->mode, 1, 1)D= $self->seek(0, 0)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
997 and 'r' eq first_char $mode
998 and '+' eq (substr $self->mode, 1, 1) || NUL
999 and $self->seek( 0, SEEK_SET )
1000 and return $self;
1001 264 ▶ $self->type or $self->$_init_type_from_fs; $self->type or $self->file;
Branch: 2 branches
BranchTrueFalseTotal
$self->type or $self->$_init_type_from_fs 222 42 264
$self->type or $self->file 242 21 263
1002 263 ▶ $self->is_open and $self->close;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_open and $self->close 6 257 263
1003  
1004 263 ▶ return $self->is_dir
Branch: 1 branch
BranchTrueFalseTotal
$self->is_dir ? : 128 135 263
1005 ? $self->$_open_dir ( $self->$_open_args( $mode, $perms ) )
1006 : $self->$_open_file( $self->$_open_args( $mode, $perms ) );
1007 }
1008  
1009 3 ▶sub parent {
Subroutine parent: called CC=3 SCAR=11.0
Pod documented
1010 3 ▶ my ($self, $count) = @_; my $parent = $self; $count ||= 1;
Condition100%2/2
$count ||= 1
l!l
12
MC/DC100%1/1
$count ||= 1
$count
Truth table100%2/2
A
A= $count
Aresult
11
00
1011  
1012 3 ▶ $parent = $self->$_constructor( $parent->dirname ) while ($count--);
Branch: 1 branch
BranchTrueFalseTotal
$count-- and do { $parent = $self->$_constructor($parent->dirname) } 4 3 7
1013  
1014 3 return $parent;
1015 }
1016  
1017 11 ▶sub pathname {
Subroutine pathname: called CC=1 SCAR=0.0
Pod documented
1018 11 return $_[ 0 ]->name;
1019 }
1020  
1021 11 ▶sub perms {
Subroutine perms: called CC=2 SCAR=7.2
Pod documented
1022 11 ▶ defined $_[ 1 ] and $_[ 0 ]->_set__perms( $_[ 1 ] ); return $_[ 0 ];
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] and $_[0]->_set__perms($_[1]) 11 0 11
1023 }
1024  
1025 43 ▶sub print {
Subroutine print: called CC=1 SCAR=0.0
Pod documented
1026 43 return shift->assert_open( 'w' )->$_print( @_ );
1027 }
1028  
1029 16 ▶sub println {
Subroutine println: called CC=1 SCAR=0.0
Pod documented
1030 16 return shift->assert_open( 'w' )->$_println( @_ );
1031 }
1032  
1033 38 ▶sub read {
Subroutine read: called CC=6 SCAR=20.5
Pod documented
1034 38 my ($self, @args) = @_; $self->assert_open;
1035  
1036 my $length = @args || $self->is_dir
1037 ? $self->io_handle->read( @args )
1038 38 ▶ : $self->io_handle->read( ${ $self->buffer },
Branch: 1 branch
BranchTrueFalseTotal
@args || $self->is_dir ? : 0 38 38
Condition33%1/3
@args or $self->is_dir
l!l&&r!l&&!r
0038
MC/DC0%0/2
@args or $self->is_dir
@args $self->is_dir
Truth table33%1/3
A or B
A= @argsB= $self->is_dir
ABresult
1X1
011
000
1039 $self->_block_size, $self->length );
1040  
1041 38 $self->error_check;
1042  
1043 38 ▶ return $length || $self->autoclose && $self->close && 0;
Condition50%4/8
$length || $self->autoclose && $self->close && 0
l!l&&r!l&&!r
3503
$self->autoclose and $self->close and 0
!ll
03
$self->autoclose and $self->close
!ll&&!rl&&r
030
MC/DC0%0/3
$length || $self->autoclose && $self->close && 0
$length $self->autoclose $self->close
Truth table25%1/4
A || B and C
A= $lengthB= $self->autocloseC= $self->close
ABCresult
1XX1
0111
00X0
0100
1044 }
1045  
1046 456 ▶sub read_dir {
Subroutine read_dir: called CC=9 SCAR=22.1
Pod documented
1047 456 ▶ my $self = shift; $self->type or $self->dir; $self->assert_open;
Branch: 1 branch
BranchTrueFalseTotal
$self->type or $self->dir 434 22 456
1048  
1049 455 ▶ $self->is_link and $self->_no_follow and $self->close and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_link and $self->_no_follow and $self->close and return 0 455 455
Condition50%3/6
$self->is_link and $self->_no_follow and $self->close
!ll&&!rl&&r
45500
$self->is_link and $self->_no_follow
!ll&&!rl&&r
44960
MC/DC0%0/3
$self->is_link and $self->_no_follow and $self->close
$self->is_link $self->_no_follow $self->close
Truth table50%2/4
A and B and C
A= $self->is_linkB= $self->_no_followC= $self->close
ABCresult
0XX0
10X0
1100
1111
1050  
1051 455 my $dir_pat = $self->_dir_pattern; my $name;
1052  
1053 455 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 1 454 455
1054 1 my @names = grep { $_ !~ $dir_pat } $self->io_handle->read;
1055  
1056 1 $self->close; return @names;
1057 }
1058  
1059 454 ▶ while (not defined $name or $name =~ $dir_pat) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name or $name =~ /$dir_pat/) 706 333 1039
Condition100%3/3
not defined $name or $name =~ /$dir_pat/
l!l&&r!l&&!r
454252333
MC/DC100%2/2
not defined $name or $name =~ /$dir_pat/
not defined $name $name =~ /$dir_pat/
Truth table100%3/3
not(A) or B
A= not defined $nameB= $name =~ /$dir_pat/
ABresult
1X1
011
000
1060 706 ▶ unless (defined ($name = $self->io_handle->read)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($name = $self->io_handle->read)) 121 585 706
1061 121 $self->close; return;
1062 }
1063 }
1064  
1065 333 return $name;
1066 }
1067  
1068 4 ▶sub rel2abs {
Subroutine rel2abs: called CC=2 SCAR=6.9
Pod documented
1069 4 my ($self, $base) = @_;
1070  
1071 4 ▶ return File::Spec->rel2abs( $self->name, defined $base ? "${base}" : undef );
Branch: 1 branch
BranchTrueFalseTotal
defined $base ? : 2 2 4
1072 }
1073  
1074 47 ▶sub relative {
Subroutine relative: called CC=1 SCAR=0.0
Pod documented
1075 47 $_[ 0 ]->_set_name( $_[ 0 ]->abs2rel ); return $_[ 0 ];
1076 }
1077  
1078 1 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
1079 1 my $self = shift; $self->close;
1080  
1081 1 $self->_assert( FALSE ); $self->_atomic( FALSE ); $self->_chomp ( FALSE );
1082 1 $self->_deep ( FALSE ); $self->_lock ( FALSE ); $self->_no_follow( FALSE );
1083 1 return $self;
1084 }
1085  
1086 2 ▶sub rmdir {
Subroutine rmdir: called CC=2 SCAR=6.9
Pod documented
1087 2 my $self = shift;
1088  
1089 2 ▶ CORE::rmdir $self->name
Branch: 1 branch
BranchTrueFalseTotal
CORE::rmdir $self->name or $self->$_throw("Path [_1] not removed: [_2]", [$self->name, $File::DataClass::IO::OS_ERROR]) 1 1 2
1090 or $self->$_throw( 'Path [_1] not removed: [_2]',
1091 [ $self->name, $OS_ERROR ] );
1092 1 return $self;
1093 }
1094  
1095 2 ▶sub rmtree {
Subroutine rmtree: called CC=1 SCAR=0.0
Pod documented
1096 2 my ($self, @args) = @_; ensure_class_loaded 'File::Path';
1097  
1098 2 return File::Path::remove_tree( $self->name, @args );
1099 }
1100  
1101 5 ▶sub seek {
Subroutine seek: called CC=3 SCAR=11.0
Pod documented
1102 5 my ($self, $posn, $whence) = @_;
1103  
1104 5 ▶ $self->is_open or $self->assert_open( is_mswin ? 'r' : 'r+' );
Branch: 2 branches
BranchTrueFalseTotal
$self->is_open or $self->assert_open(&is_mswin() ? "r" : "r+") 4 1 5
&is_mswin() ? : 0 1 1
1105 5 CORE::seek $self->io_handle, $posn, $whence; $self->error_check;
1106 5 return $self;
1107 }
1108  
1109 1 ▶sub separator {
Subroutine separator: called CC=2 SCAR=7.2
Pod documented
1110 1 ▶ defined $_[ 1 ] and $_[ 0 ]->_separator( $_[ 1 ] ); return $_[ 0 ];
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] and $_[0]->_separator($_[1]) 1 0 1
1111 }
1112  
1113 144 ▶sub set_binmode {
Subroutine set_binmode: called CC=3 SCAR=11.0
Pod documented
1114 144 my $self = shift;
1115  
1116 144 ▶ is_ntfs and $self->$_push_layer(); # uncoverable branch true
Branch: 1 branch
BranchTrueFalseTotal
&is_ntfs() and $self->$_push_layer 0 144 144
1117  
1118 144 $self->$_sane_binmode( $_ ) for (@{ $self->_layers });
1119  
1120 144 return $self;
1121 }
1122  
1123 144 ▶sub set_lock {
Subroutine set_lock: called CC=6 SCAR=17.9
Pod documented
1124 144 ▶ my $self = shift; $self->_lock or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock or return 67 77 144
1125  
1126 67 ▶ my $async = $self->_lock == LOCK_NONBLOCKING ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock == 2 ? : 1 66 67
1127 67 ▶ my $mode = $self->mode eq 'r' ? LOCK_SH : LOCK_EX;
Branch: 1 branch
BranchTrueFalseTotal
$self->mode eq 'r' ? : 38 29 67
1128  
1129 67 ▶ $async and $mode |= LOCK_NB;
Branch: 1 branch
BranchTrueFalseTotal
$async and $mode |= 4 1 66 67
1130 67 ▶ $self->_set_have_lock( (flock $self->io_handle, $mode) ? TRUE : FALSE );
Branch: 1 branch
BranchTrueFalseTotal
flock($self->io_handle, $mode) ? : 67 0 67
1131 67 return $self;
1132 }
1133  
1134 1 ▶sub sibling {
Subroutine sibling: called CC=1 SCAR=0.0
Pod documented
1135 1 my $self = shift; return $self->parent->child( @_ );
1136 }
1137  
1138 13 ▶sub slurp {
Subroutine slurp: called CC=3 SCAR=11.0
Pod documented
1139 13 my $self = shift; my $slurp = $self->all;
1140  
1141 12 ▶ wantarray or return $slurp; local $RS = $self->_separator;
Branch: 1 branch
BranchTrueFalseTotal
wantarray or return $slurp 2 10 12
1142  
1143 2 ▶ $self->_chomp or return split m{ (?<=\Q$RS\E) }mx, $slurp;
Branch: 1 branch
BranchTrueFalseTotal
$self->_chomp or return split(/ (?<=\Q$File::DataClass::IO::RS\E) /mx, $slurp, 0) 2 0 2
1144  
1145 2 return map { CORE::chomp; $_ } split m{ (?<=\Q$RS\E) }mx, $slurp;
1146 }
1147  
1148 1 ▶sub splitdir {
Subroutine splitdir: called CC=1 SCAR=0.0
Pod documented
1149 1 return File::Spec->splitdir( $_[ 0 ]->name );
1150 }
1151  
1152 1 ▶sub splitpath {
Subroutine splitpath: called CC=1 SCAR=0.0
Pod documented
1153 1 return File::Spec->splitpath( $_[ 0 ]->name );
1154 }
1155  
1156 348 ▶sub stat {
Subroutine stat: called CC=4 SCAR=14.0
Pod documented
1157 348 my $self = shift; my $exists = my @fields = stat( $self->name );
1158  
1159 348 ▶ $exists or $self->is_open or return;
Branch: 1 branch
BranchTrueFalseTotal
$exists or $self->is_open or return 346 2 348
Condition66%2/3
$exists or $self->is_open
l!l&&r!l&&!r
34602
MC/DC50%1/2
$exists or $self->is_open
$exists $self->is_open
Truth table66%2/3
A or B
A= $existsB= $self->is_open
ABresult
1X1
011
000
1160  
1161 346 my %stat_hash = ( id => $self->filename );
1162  
1163 346 ▶ @stat_hash{ STAT_FIELDS() } = $exists ? @fields : stat( $self->io_handle );
Branch: 1 branch
BranchTrueFalseTotal
$exists ? : 346 0 346
1164  
1165 346 return \%stat_hash;
1166 }
1167  
1168 4 ▶sub substitute {
Subroutine substitute: called CC=6 SCAR=17.9
Pod documented
1169 4 ▶ my ($self, $search, $replace) = @_; $replace //= NUL;
Condition100%2/2
$replace //= ""
l!l
31
MC/DC100%1/1
$replace //= ""
$replace
Truth table100%2/2
A
A= $replace
Aresult
11
00
1170  
1171 4 ▶ (defined $search and CORE::length $search) or return $self;
Branch: 1 branch
BranchTrueFalseTotal
defined $search and CORE::length $search or return $self 2 2 4
Condition100%3/3
defined $search and CORE::length $search
!ll&&!rl&&r
112
MC/DC100%2/2
defined $search and CORE::length $search
defined $search CORE::length $search
Truth table100%3/3
A and B
A= defined $searchB= CORE::length $search
ABresult
0X0
100
111
1172  
1173 2 my $perms = $self->$_untainted_perms;
1174 2 my $wtr = $self->$_constructor( $self->name )->atomic;
1175  
1176 2 ▶ $perms and $wtr->perms( $perms );
Branch: 1 branch
BranchTrueFalseTotal
$perms and $wtr->perms($perms) 2 0 2
1177  
1178 2 for ($self->getlines) { s{ $search }{$replace}gmx; $wtr->print( $_ ) }
1179  
1180 2 $self->close; $wtr->close;
1181 2 return $self;
1182 }
1183  
1184 3 ▶sub tail {
Subroutine tail: called CC=5 SCAR=16.2
Pod documented
1185 3 ▶ my ($self, $lines, @args) = @_; my @res; $lines //= 10; $self->close;
Condition100%2/2
$lines //= 10
l!l
12
MC/DC100%1/1
$lines //= 10
$lines
Truth table100%2/2
A
A= $lines
Aresult
11
00
1186  
1187 3 ▶ while ($lines--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines--) 14 2 16
1188 14 ▶ unshift @res, ($self->$_getline_backwards( @args ) or last);
Condition50%1/2
$self->$_getline_backwards(@args) || (last)
l!l
130
MC/DC0%0/1
$self->$_getline_backwards(@args) || (last)
$self->$_getline_backwards(@args)
Truth table50%1/2
A
A= $self->$_getline_backwards(@args)
Aresult
11
00
1189 }
1190  
1191 2 $self->close;
1192 2 ▶ return wantarray ? @res : join NUL, @res;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
1193 }
1194  
1195 3 ▶sub tell {
Subroutine tell: called CC=3 SCAR=13.1
Pod documented
1196 3 my $self = shift;
1197  
1198 3 ▶ $self->is_open or $self->assert_open( is_mswin ? 'r' : 'r+' );
Branch: 2 branches
BranchTrueFalseTotal
$self->is_open or $self->assert_open(&is_mswin() ? "r" : "r+") 3 0 3
&is_mswin() ? : 0 0 0
1199  
1200 3 return CORE::tell $self->io_handle;
1201 }
1202  
1203 2 ▶sub tempfile {
Subroutine tempfile: called CC=4 SCAR=13.9
Pod documented
1204 2 my ($self, $tmplt) = @_; my $tempdir;
1205  
1206 2 ▶ ensure_class_loaded 'File::Temp'; $tmplt ||= '%6.6dXXXX';
Condition50%1/2
$tmplt ||= "%6.6dXXXX"
l!l
02
MC/DC0%0/1
$tmplt ||= "%6.6dXXXX"
$tmplt
Truth table50%1/2
A
A= $tmplt
Aresult
11
00
1207  
1208 2 ▶ ($tempdir = $self->name and -d $tempdir) or $tempdir = File::Spec->tmpdir;
Branch: 1 branch
BranchTrueFalseTotal
$tempdir = $self->name and -d $tempdir or $tempdir = "File::Spec"->tmpdir 1 1 2
Condition66%2/3
$tempdir = $self->name and -d $tempdir
!ll&&!rl&&r
101
MC/DC50%1/2
$tempdir = $self->name and -d $tempdir
$tempdir = $self->name -d $tempdir
Truth table66%2/3
A and B
A= $tempdir = $self->nameB= -d $tempdir
ABresult
0X0
100
111
1209  
1210 2 my $tmpfh = File::Temp->new
1211 ( DIR => $tempdir, TEMPLATE => (sprintf $tmplt, $PID) );
1212 2 my $t = $self->$_constructor( $tmpfh->filename )->file;
1213  
1214 2 $t->_set_io_handle( $tmpfh ); $t->_set_is_open( TRUE );
1215 2 $t->_set_mode( 'w+' );
1216 2 return $t;
1217 }
1218  
1219 7 ▶sub touch {
Subroutine touch: called CC=4 SCAR=14.0
Pod documented
1220 7 ▶ my ($self, $time) = @_; CORE::length $self->name or return; $time //= time;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $self->name or return 7 0 7
Condition100%2/2
$time //= time
l!l
16
MC/DC100%1/1
$time //= time
$time
Truth table100%2/2
A
A= $time
Aresult
11
00
1221  
1222 7 ▶ -e $self->name or $self->$_open_file( $self->$_open_args( 'w' ) )->close;
Branch: 1 branch
BranchTrueFalseTotal
-e $self->name or $self->$_open_file($self->$_open_args("w"))->close 0 7 7
1223  
1224 7 utime $time, $time, $self->name;
1225 7 return $self;
1226 }
1227  
1228 27 ▶sub unlink {
Subroutine unlink: called CC=1 SCAR=0.0
Pod documented
1229 27 return unlink $_[ 0 ]->name;
1230 }
1231  
1232 288 ▶sub unlock {
Subroutine unlock: called CC=4 SCAR=13.9
Pod documented
1233 288 ▶ my $self = shift; $self->_lock or return; my $handle = $self->io_handle;
Branch: 1 branch
BranchTrueFalseTotal
$self->_lock or return 69 219 288
1234  
1235 69 ▶ $handle and $handle->opened and flock $handle, LOCK_UN;
Branch: 1 branch
BranchTrueFalseTotal
$handle and $handle->opened and flock $handle, 8 67 2 69
Condition66%2/3
$handle and $handle->opened
!ll&&!rl&&r
2067
MC/DC50%1/2
$handle and $handle->opened
$handle $handle->opened
Truth table66%2/3
A and B
A= $handleB= $handle->opened
ABresult
0X0
100
111
1236 69 $self->_set_have_lock( FALSE );
1237 69 return $self;
1238 }
1239  
1240 1 ▶sub utf8 {
Subroutine utf8: called CC=1 SCAR=0.0
Pod documented
1241 1 $_[ 0 ]->encoding( 'UTF-8' ); return $_[ 0 ];
1242 }
1243  
1244 1 ▶sub visit {
Subroutine visit: called CC=4 SCAR=13.9
Pod documented
1245 1 my ($self, $cb, $args) = @_;
1246  
1247 1 my $iter = $self->iterator( $args ); my $state = {};
1248  
1249 1 ▶ while (defined (my $entry = $iter->())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = &$iter())) 9 0 9
1250 9 local $_ = $entry; my $r = $cb->( $entry, $state );
1251  
1252 9 ▶ ref $r and not ${ $r } and last;
Branch: 1 branch
BranchTrueFalseTotal
ref $r and not ${$r;} and last 1 8 9
Condition100%3/3
ref $r and not ${$r;}
!ll&&!rl&&r
171
MC/DC100%2/2
ref $r and not ${$r;}
ref $r not ${$r;}
Truth table100%3/3
A and not(B)
A= ref $rB= not ${$r;}
ABresult
0X0
100
111
1253 }
1254  
1255 1 return $state;
1256 }
1257  
1258 15 ▶sub write {
Subroutine write: called CC=3 SCAR=11.2
Pod documented
1259 15 my ($self, @args) = @_; $self->assert_open( 'w' );
1260  
1261 my $length = @args
1262 ? $self->io_handle->write( @args )
1263 15 ▶ : $self->io_handle->write( ${ $self->buffer }, $self->length );
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 0 15 15
1264  
1265 15 ▶ $self->error_check; scalar @args or $self->clear;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args or $self->clear 0 15 15
1266 15 return $length;
1267 }
1268  
1269 # Method installer
1270 56 ▶my $_proxy = sub { # Methods handled by the IO::Handle object
Subroutine __ANON__: called CC=2 SCAR=6.9
1271 56 my ($proxy, $chain, $mode) = @_;
1272  
1273 56 ▶ my $package = caller; $package->can( $proxy ) and return;
Branch: 1 branch
BranchTrueFalseTotal
$package->can($proxy) and return 0 56 56
1274  
1275 9 ▶ install_sub { into => $package, as => $proxy, code => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
1276 9 ▶ my $self = shift; defined $mode and $self->assert_open( $mode );
Branch: 1 branch
BranchTrueFalseTotal
defined $mode and $self->assert_open($mode) 4 5 9
1277  
1278 9 ▶ defined $self->io_handle or throw InvocantUndefined, [ $proxy ];
Branch: 1 branch
BranchTrueFalseTotal
defined $self->io_handle or &throw(InvocantUndefined(), [$proxy]) 8 1 9
1279  
1280 8 my @results = $self->io_handle->$proxy( @_ ); # Mustn't copy stack args
1281  
1282 8 ▶ $self->error_check; $chain and return $self;
Branch: 1 branch
BranchTrueFalseTotal
$chain and return $self 1 7 8
1283  
1284 7 ▶ return wantarray ? @results : $results[ 0 ];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 7 7
1285 56 } };
1286 7 };
1287  
1288 7 $_proxy->( 'autoflush', TRUE );
1289 7 $_proxy->( 'eof' );
1290 7 $_proxy->( 'fileno' );
1291 7 $_proxy->( 'flush', TRUE );
1292 7 $_proxy->( 'getc', FALSE, 'r' );
1293 7 $_proxy->( 'sysread', FALSE, O_RDONLY );
1294 7 $_proxy->( 'syswrite', FALSE, O_CREAT | O_WRONLY );
1295 7 $_proxy->( 'truncate', TRUE );
1296  
1297 7 1;
1298  
1299 __END__
« lib/File/DataClass/Functions.pm ↑ Summary lib/File/DataClass/Cache.pm »