All/Filesys.pm

filter: Statementstmt 84.1% 69 / 82 Branchbran 71.8% 23 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 73.9% 17 / 23 Podpod 0.0% 0 / 17 totaltotal 70.7% 109 / 154 CC 17 SCAR 11.2
CC
17
Cov
81%
rename
12.0
is_absolute
4.0
utime
3.1
CRAP 3.1
« All/Dir.pm ↑ Summary All/STDIO.pm »
1 59 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package IO::All::Filesys;
3  
4 59 ▶use IO::All::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 59 ▶use Fcntl qw(:flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 59 my %spec_map = (
8 unix => 'Unix',
9 win32 => 'Win32',
10 vms => 'VMS',
11 mac => 'Mac',
12 os2 => 'OS2',
13 );
14 23 ▶sub os {
Subroutine os: called CC=1 SCAR=0.0
Pod undocumented
15 23 my ($self, $type) = @_;
16  
17 23 my ($v, $d, $f) = $self->_spec_class->splitpath($self->name);
18 23 my @d = $self->_spec_class->splitdir($d);
19  
20 23 $self->_spec_class($spec_map{$type});
21  
22 23 $self->name( $self->_spec_class->catfile( @d, $f ) );
23  
24 23 return $self
25 }
26  
27 0 ▶sub exists { my $self = shift; -e $self->name }
Subroutine exists: not called CC=1 SCAR=6.9
Pod undocumented
28  
29 12 ▶sub filename {
Subroutine filename: called CC=1 SCAR=0.0
Pod undocumented
30 12 my $self = shift;
31 12 my $filename;
32 12 (undef, undef, $filename) = $self->splitpath;
33 12 return $filename;
34 }
35  
36 2 ▶sub ext {
Subroutine ext: called CC=2 SCAR=7.2
Pod undocumented
37 2 my $self = shift;
38  
39 2 ▶ return $1 if $self->filename =~ m/\.([^\.]+)$/
Branch: 1 branch
BranchTrueFalseTotal
if $self->filename =~ /\.([^\.]+)$/ 2 0 2
40 }
41 {
42 59 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
43 59 *extension = \&ext;
44 }
45  
46 0 ▶sub mimetype {
Subroutine mimetype: not called CC=1 SCAR=6.9
Pod undocumented
47 0 require File::MimeInfo;
48 0 return File::MimeInfo::mimetype($_[0]->filename)
49 }
50  
51 372 ▶sub is_absolute {
Subroutine is_absolute: called CC=4 SCAR=13.9
Pod undocumented
52 372 my $self = shift;
53 372 ▶ return *$self->{is_absolute} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 17 355 372
54 return *$self->{is_absolute}
55 355 ▶ if defined *$self->{is_absolute};
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"is_absolute"} 204 151 355
56 151 ▶ *$self->{is_absolute} = IO::All::is_absolute($self) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
IO::All::is_absolute($self) ? : 11 140 151
57 }
58  
59 0 ▶sub is_executable { my $self = shift; -x $self->name }
Subroutine is_executable: not called CC=1 SCAR=6.9
Pod undocumented
60 0 ▶sub is_readable { my $self = shift; -r $self->name }
Subroutine is_readable: not called CC=1 SCAR=6.9
Pod undocumented
61 0 ▶sub is_writable { my $self = shift; -w $self->name }
Subroutine is_writable: not called CC=1 SCAR=6.9
Pod undocumented
62 {
63 59 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
64 59 *is_writeable = \&is_writable;
65 }
66  
67 3241 ▶sub pathname {
Subroutine pathname: called CC=3 SCAR=11.0
Pod undocumented
68 3241 my $self = shift;
69 3241 ▶ return *$self->{pathname} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 7 3234 3241
70 3234 ▶ return *$self->{pathname} if defined *$self->{pathname};
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"pathname"} 9 3225 3234
71 3225 return $self->name;
72 }
73  
74 2 ▶sub relative {
Subroutine relative: called CC=3 SCAR=11.0
Pod undocumented
75 2 my $self = shift;
76 2 ▶ if (my $base = $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $base = $_[0]) { } 1 1 2
elsif ($self->is_absolute) { } 1 0 1
77 1 $self->pathname(File::Spec->abs2rel($self->pathname, $base))
78 } elsif ($self->is_absolute) {
79 1 $self->pathname(File::Spec->abs2rel($self->pathname))
80 }
81 2 $self->is_absolute(0);
82 2 return $self;
83 }
84  
85 0 ▶sub rename {
Subroutine rename: not called CC=3 SCAR=24.8
Pod undocumented
86 0 my $self = shift;
87 0 my $new = shift;
88 0 ▶ rename($self->name, "$new")
Branch: 2 branches
BranchTrueFalseTotal
CORE::rename($self->name, "$new") ? : 0 0 0
UNIVERSAL::isa($new, 'IO::All') ? : 0 0 0
89 ? UNIVERSAL::isa($new, 'IO::All')
90 ? $new
91 : $self->_constructor->($new)
92 : undef;
93 }
94  
95 115 ▶sub set_lock {
Subroutine set_lock: called CC=3 SCAR=11.0
Pod undocumented
96 115 my $self = shift;
97 115 ▶ return unless $self->_lock;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_lock 112 3 115
98 3 my $io_handle = $self->io_handle;
99 3 ▶ my $flag = $self->mode =~ /^>>?$/
Branch: 1 branch
BranchTrueFalseTotal
$self->mode =~ /^>>?$/ ? : 2 1 3
100 ? LOCK_EX
101 : LOCK_SH;
102 3 flock $io_handle, $flag;
103 }
104  
105 1 ▶sub stat {
Subroutine stat: called CC=2 SCAR=7.1
Pod undocumented
106 1 my $self = shift;
107 1 ▶ return IO::All::stat($self, @_)
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_open 0 1 1
108 if $self->is_open;
109 1 CORE::stat($self->pathname);
110 }
111  
112 1 ▶sub touch {
Subroutine touch: called CC=1 SCAR=0.0
Pod undocumented
113 1 my $self = shift;
114 1 $self->utime;
115 }
116  
117 121 ▶sub unlock {
Subroutine unlock: called CC=2 SCAR=6.9
Pod undocumented
118 121 my $self = shift;
119 121 ▶ flock $self->io_handle, LOCK_UN
Branch: 1 branch
BranchTrueFalseTotal
if $self->_lock 4 117 121
120 if $self->_lock;
121 }
122  
123 1 ▶sub utime {
Subroutine utime: called CC=3 SCAR=11.2
Pod undocumented
124 1 my $self = shift;
125 1 my $atime = shift;
126 1 my $mtime = shift;
127 1 ▶ $atime = time unless defined $atime;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $atime 1 0 1
128 1 ▶ $mtime = $atime unless defined $mtime;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mtime 1 0 1
129 1 utime($atime, $mtime, $self->name);
130 1 return $self;
131 }
132  
133 59 1;
« All/Dir.pm ↑ Summary All/STDIO.pm »