| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 54 | return *$self->{is_absolute} | ||||||||||||||
| 55 | 355 | ▶ | if defined *$self->{is_absolute}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 56 | 151 | ▶ | *$self->{is_absolute} = IO::All::is_absolute($self) ? 1 : 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 70 | 3234 | ▶ | return *$self->{pathname} if defined *$self->{pathname}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 98 | 3 | my $io_handle = $self->io_handle; | |||||||||||||
| 99 | 3 | ▶ | my $flag = $self->mode =~ /^>>?$/ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 128 | 1 | ▶ | $mtime = $atime unless defined $mtime; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 129 | 1 | utime($atime, $mtime, $self->name); | |||||||||||||
| 130 | 1 | return $self; | |||||||||||||
| 131 | } | ||||||||||||||
| 132 | |||||||||||||||
| 133 | 59 | 1; | |||||||||||||