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/Base.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 sub os {
15 23 ▶ my ($self, $type) = @_;
Subroutine os: called CC=1 SCAR=0.0
Pod undocumented
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 sub filename {
30 12 ▶ my $self = shift;
Subroutine filename: called CC=1 SCAR=0.0
Pod undocumented
31 12 my $filename;
32 12 (undef, undef, $filename) = $self->splitpath;
33 12 return $filename;
34 }
35  
36 sub ext {
37 2 ▶ my $self = shift;
Subroutine ext: called CC=2 SCAR=7.2
Pod undocumented
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 sub mimetype {
47 0 ▶ require File::MimeInfo;
Subroutine mimetype: not called CC=1 SCAR=6.9
Pod undocumented
48 0 return File::MimeInfo::mimetype($_[0]->filename)
49 }
50  
51 sub is_absolute {
52 369 ▶ my $self = shift;
Subroutine is_absolute: called CC=4 SCAR=13.9
Pod undocumented
53 369 ▶ return *$self->{is_absolute} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 17 352 369
54 return *$self->{is_absolute}
55 352 ▶ if defined *$self->{is_absolute};
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"is_absolute"} 202 150 352
56 150 ▶ *$self->{is_absolute} = IO::All::is_absolute($self) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
IO::All::is_absolute($self) ? : 11 139 150
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 sub pathname {
68 3420 ▶ my $self = shift;
Subroutine pathname: called CC=3 SCAR=11.0
Pod undocumented
69 3420 ▶ return *$self->{pathname} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 7 3413 3420
70 3413 ▶ return *$self->{pathname} if defined *$self->{pathname};
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"pathname"} 9 3404 3413
71 3404 return $self->name;
72 }
73  
74 sub relative {
75 2 ▶ my $self = shift;
Subroutine relative: called CC=3 SCAR=11.0
Pod undocumented
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 sub rename {
86 0 ▶ my $self = shift;
Subroutine rename: not called CC=3 SCAR=24.8
Pod undocumented
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 sub set_lock {
96 115 ▶ my $self = shift;
Subroutine set_lock: called CC=3 SCAR=11.0
Pod undocumented
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 sub stat {
106 1 ▶ my $self = shift;
Subroutine stat: called CC=2 SCAR=7.1
Pod undocumented
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 sub touch {
113 1 ▶ my $self = shift;
Subroutine touch: called CC=1 SCAR=0.0
Pod undocumented
114 1 $self->utime;
115 }
116  
117 sub unlock {
118 121 ▶ my $self = shift;
Subroutine unlock: called CC=2 SCAR=6.9
Pod undocumented
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 sub utime {
124 1 ▶ my $self = shift;
Subroutine utime: called CC=3 SCAR=11.2
Pod undocumented
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/Base.pm ↑ Summary All/STDIO.pm »