| 1 | package File::System::Real; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||
| 6 | 7 | our $VERSION = '1.15'; | |||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||
|
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::Copy::Recursive; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use File::Glob (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use File::Path (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use FileHandle; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | 7 | ▶ | use base 'File::System::Object'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | File::System::Real - A file system module based on the real file system | ||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | use File::System; | ||||||||||||||||||||||||||||||||||||||
| 25 | $root = File::System->new('Real', root => '/usr/local'); | ||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||
| 29 | This is the most basic file system implementation. It is purely implemented within terms of a real file system. | ||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | =head1 OPTIONS | ||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||
| 33 | This file system module accepts only a single object, C<root>. If not given, the current working directory is assumed for the value C<root>. All files returned by the file system will be rooted at the given (or assumed) point. | ||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | 13 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 38 | 13 | my $class = shift; | |||||||||||||||||||||||||||||||||||||
| 39 | 13 | my %args = @_; | |||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | 13 | ▶ | $args{root} ||= '.'; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"root"} ||= "."
MC/DC0%0/1
$args{"root"} ||= "."
$args{"root"}
Truth table50%1/2
A
A= $args{"root"}
| |||||||||||||||||||||||||||||||||||||||
| 42 | 13 | $args{root} = File::Spec->rel2abs($args{root}); | |||||||||||||||||||||||||||||||||||||
| 43 | 13 | $args{root} = $class->normalize_path($args{root}); | |||||||||||||||||||||||||||||||||||||
| 44 | 13 | my $root = File::Spec->canonpath($args{root}); | |||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | 13 | ▶ | -e $root or croak "Sorry, root $root does not exist!"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 47 | 13 | ▶ | -d $root or croak "Sorry, root $root is not a directory!"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | 13 | return bless { | |||||||||||||||||||||||||||||||||||||
| 50 | fs_root => $root, | ||||||||||||||||||||||||||||||||||||||
| 51 | path => '/', | ||||||||||||||||||||||||||||||||||||||
| 52 | fullpath => $root, | ||||||||||||||||||||||||||||||||||||||
| 53 | }, $class; | ||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||
| 56 | 983 | ▶ | sub is_valid { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 57 | 983 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 58 | 983 | return -e $self->{fullpath}; | |||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||
| 61 | 20 | ▶ | sub root { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
root: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 62 | 20 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||
| 64 | return bless { | ||||||||||||||||||||||||||||||||||||||
| 65 | fs_root => $self->{fs_root}, | ||||||||||||||||||||||||||||||||||||||
| 66 | path => '/', | ||||||||||||||||||||||||||||||||||||||
| 67 | fullpath => $self->{fs_root}, | ||||||||||||||||||||||||||||||||||||||
| 68 | 20 | }, ref $self; | |||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | 865 | ▶ | sub exists { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 72 | 865 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 73 | 865 | ▶ | my $path = shift || $self->path; | ||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $self->path
MC/DC0%0/2
shift() || $self->path
shift()
$self->path
Truth table66%2/3
A || B
A= shift()B= $self->path
| |||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||
| 75 | 865 | return -e $self->normalize_real_path($path); | |||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | 28236 | ▶ | sub lookup { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
lookup: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 79 | 28236 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 80 | 28236 | my $path = shift; | |||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||
| 82 | 28236 | my $abspath = $self->normalize_path($path); | |||||||||||||||||||||||||||||||||||||
| 83 | 28236 | my $fullpath = $self->normalize_real_path($path); | |||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||
| 85 | return undef | ||||||||||||||||||||||||||||||||||||||
| 86 | 28236 | ▶ | unless -e $fullpath; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | return bless { | ||||||||||||||||||||||||||||||||||||||
| 89 | fs_root => $self->{fs_root}, | ||||||||||||||||||||||||||||||||||||||
| 90 | 28067 | path => $abspath, | |||||||||||||||||||||||||||||||||||||
| 91 | fullpath => $fullpath, | ||||||||||||||||||||||||||||||||||||||
| 92 | }, ref $self; | ||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | 320 | ▶ | sub glob { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
glob: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 96 | 320 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 97 | 320 | my $glob = shift; | |||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||
| 99 | 320 | my $absglob = $self->normalize_path($glob); | |||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | 320 | my $fullglob = $self->normalize_real_path($absglob); | |||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||
| 103 | return sort map { | ||||||||||||||||||||||||||||||||||||||
| 104 | 320 | s/^$self->{fs_root}//; | |||||||||||||||||||||||||||||||||||||
| 105 | bless { | ||||||||||||||||||||||||||||||||||||||
| 106 | fs_root => $self->{fs_root}, | ||||||||||||||||||||||||||||||||||||||
| 107 | 228 | path => $self->normalize_path($_), | |||||||||||||||||||||||||||||||||||||
| 108 | fullpath => $self->normalize_real_path($_), | ||||||||||||||||||||||||||||||||||||||
| 109 | }, ref $self | ||||||||||||||||||||||||||||||||||||||
| 110 | } File::Glob::bsd_glob($fullglob); | ||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||
| 113 | 2569 | ▶ | sub properties { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
properties: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 114 | 2569 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | 2569 | return qw/ | |||||||||||||||||||||||||||||||||||||
| 117 | basename | ||||||||||||||||||||||||||||||||||||||
| 118 | dirname | ||||||||||||||||||||||||||||||||||||||
| 119 | path | ||||||||||||||||||||||||||||||||||||||
| 120 | object_type | ||||||||||||||||||||||||||||||||||||||
| 121 | dev | ||||||||||||||||||||||||||||||||||||||
| 122 | ino | ||||||||||||||||||||||||||||||||||||||
| 123 | mode | ||||||||||||||||||||||||||||||||||||||
| 124 | nlink | ||||||||||||||||||||||||||||||||||||||
| 125 | uid | ||||||||||||||||||||||||||||||||||||||
| 126 | gid | ||||||||||||||||||||||||||||||||||||||
| 127 | rdev | ||||||||||||||||||||||||||||||||||||||
| 128 | size | ||||||||||||||||||||||||||||||||||||||
| 129 | atime | ||||||||||||||||||||||||||||||||||||||
| 130 | mtime | ||||||||||||||||||||||||||||||||||||||
| 131 | ctime | ||||||||||||||||||||||||||||||||||||||
| 132 | blksize | ||||||||||||||||||||||||||||||||||||||
| 133 | blocks | ||||||||||||||||||||||||||||||||||||||
| 134 | /; | ||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||
| 137 | 364 | ▶ | sub settable_properties { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
settable_properties: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 138 | 364 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||
| 140 | 364 | return qw/ | |||||||||||||||||||||||||||||||||||||
| 141 | mode | ||||||||||||||||||||||||||||||||||||||
| 142 | uid | ||||||||||||||||||||||||||||||||||||||
| 143 | gid | ||||||||||||||||||||||||||||||||||||||
| 144 | atime | ||||||||||||||||||||||||||||||||||||||
| 145 | mtime | ||||||||||||||||||||||||||||||||||||||
| 146 | /; | ||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||
| 149 | 1690 | ▶ | sub _stat { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_stat: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 150 | 1690 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||
| 152 | 1690 | my @stat = stat $self->{fullpath}; | |||||||||||||||||||||||||||||||||||||
| 153 | 1690 | return \@stat; | |||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||
| 156 | 91152 | ▶ | sub get_property { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_property: called CC=20 SCAR=36.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 157 | 91152 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 158 | 91152 | local $_ = shift; | |||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||
| 160 | SWITCH: { | ||||||||||||||||||||||||||||||||||||||
| 161 | 91152 | ▶ | /^basename$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 162 | 2281 | return $self->basename_of_path($self->{path}); | |||||||||||||||||||||||||||||||||||||
| 163 | }; | ||||||||||||||||||||||||||||||||||||||
| 164 | 88871 | ▶ | /^dirname$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 165 | 2647 | return $self->dirname_of_path($self->{path}); | |||||||||||||||||||||||||||||||||||||
| 166 | }; | ||||||||||||||||||||||||||||||||||||||
| 167 | 86224 | ▶ | /^path$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 168 | 21863 | return $self->{path}; | |||||||||||||||||||||||||||||||||||||
| 169 | }; | ||||||||||||||||||||||||||||||||||||||
| 170 | 64361 | ▶ | /^object_type$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 171 | 62671 | my $result = ''; | |||||||||||||||||||||||||||||||||||||
| 172 | 62671 | ▶ | $result .= 'd' if -d $self->{fullpath}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 173 | 62671 | ▶ | $result .= 'f' if -f $self->{fullpath}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 174 | 62671 | return $result; | |||||||||||||||||||||||||||||||||||||
| 175 | }; | ||||||||||||||||||||||||||||||||||||||
| 176 | 1690 | ▶ | /^dev$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return $self->_stat->[0]; | |||||||||||||||||||||||||||||||||||||
| 178 | }; | ||||||||||||||||||||||||||||||||||||||
| 179 | 1690 | ▶ | /^ino$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 180 | 0 | return $self->_stat->[1]; | |||||||||||||||||||||||||||||||||||||
| 181 | }; | ||||||||||||||||||||||||||||||||||||||
| 182 | 1690 | ▶ | /^mode$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 183 | 338 | return $self->_stat->[2]; | |||||||||||||||||||||||||||||||||||||
| 184 | }; | ||||||||||||||||||||||||||||||||||||||
| 185 | 1352 | ▶ | /^nlink$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return $self->_stat->[3]; | |||||||||||||||||||||||||||||||||||||
| 187 | }; | ||||||||||||||||||||||||||||||||||||||
| 188 | 1352 | ▶ | /^uid$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 189 | 0 | return $self->_stat->[4]; | |||||||||||||||||||||||||||||||||||||
| 190 | }; | ||||||||||||||||||||||||||||||||||||||
| 191 | 1352 | ▶ | /^gid$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 192 | 0 | return $self->_stat->[5]; | |||||||||||||||||||||||||||||||||||||
| 193 | }; | ||||||||||||||||||||||||||||||||||||||
| 194 | 1352 | ▶ | /^rdev$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 195 | 0 | return $self->_stat->[6]; | |||||||||||||||||||||||||||||||||||||
| 196 | }; | ||||||||||||||||||||||||||||||||||||||
| 197 | 1352 | ▶ | /^size$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 198 | 0 | return $self->_stat->[7]; | |||||||||||||||||||||||||||||||||||||
| 199 | }; | ||||||||||||||||||||||||||||||||||||||
| 200 | 1352 | ▶ | /^atime$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 201 | 676 | return $self->_stat->[8]; | |||||||||||||||||||||||||||||||||||||
| 202 | }; | ||||||||||||||||||||||||||||||||||||||
| 203 | 676 | ▶ | /^mtime$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 204 | 676 | return $self->_stat->[9]; | |||||||||||||||||||||||||||||||||||||
| 205 | }; | ||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | /^ctime$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return $self->_stat->[10]; | |||||||||||||||||||||||||||||||||||||
| 208 | }; | ||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | /^blksize$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 210 | 0 | return $self->_stat->[11]; | |||||||||||||||||||||||||||||||||||||
| 211 | }; | ||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | /^blocks$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 213 | 0 | return $self->_stat->[12]; | |||||||||||||||||||||||||||||||||||||
| 214 | }; | ||||||||||||||||||||||||||||||||||||||
| 215 | DEFAULT: { | ||||||||||||||||||||||||||||||||||||||
| 216 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||
| 221 | 1014 | ▶ | sub set_property { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
set_property: called CC=6 SCAR=19.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 222 | 1014 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 223 | 1014 | local $_ = shift; | |||||||||||||||||||||||||||||||||||||
| 224 | 1014 | my $value = shift; | |||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||
| 226 | SWITCH: { | ||||||||||||||||||||||||||||||||||||||
| 227 | 1014 | ▶ | /^mode$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 228 | 338 | chmod $value, $self->{fullpath}; | |||||||||||||||||||||||||||||||||||||
| 229 | 338 | last SWITCH; | |||||||||||||||||||||||||||||||||||||
| 230 | }; | ||||||||||||||||||||||||||||||||||||||
| 231 | 676 | ▶ | /^uid$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 232 | 0 | chown $value, $self->get_property('gid'), $self->{fullpath}; | |||||||||||||||||||||||||||||||||||||
| 233 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||
| 234 | }; | ||||||||||||||||||||||||||||||||||||||
| 235 | 676 | ▶ | /^gid$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 236 | 0 | chown $self->get_property('uid'), $value, $self->{fullpath}; | |||||||||||||||||||||||||||||||||||||
| 237 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||
| 238 | }; | ||||||||||||||||||||||||||||||||||||||
| 239 | 676 | ▶ | /^atime$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 240 | 338 | utime $value, $self->get_property('mtime'), $self->{fullpath}; | |||||||||||||||||||||||||||||||||||||
| 241 | 338 | last SWITCH; | |||||||||||||||||||||||||||||||||||||
| 242 | }; | ||||||||||||||||||||||||||||||||||||||
| 243 | 338 | ▶ | /^mtime$/ && do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 244 | 338 | utime $self->get_property('atime'), $value, $self->{fullpath}; | |||||||||||||||||||||||||||||||||||||
| 245 | 338 | last SWITCH; | |||||||||||||||||||||||||||||||||||||
| 246 | }; | ||||||||||||||||||||||||||||||||||||||
| 247 | DEFAULT: { | ||||||||||||||||||||||||||||||||||||||
| 248 | 0 | croak "Cannot set unknown property '$_'"; | |||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||
| 253 | 10 | ▶ | sub is_creatable { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_creatable: called CC=4 SCAR=15.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 254 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 255 | 10 | my $path = shift; | |||||||||||||||||||||||||||||||||||||
| 256 | 10 | my $type = shift; | |||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||
| 258 | 10 | ▶ | defined $type | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 259 | or croak "No type argument given."; | ||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||
| 261 | 10 | ▶ | return ($type eq 'f' || $type eq 'd') && !$self->exists($path); | ||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
($type eq 'f' || $type eq 'd') && !$self->exists($path)
$type eq "f" or $type eq "d"
MC/DC0%0/3
($type eq 'f' || $type eq 'd') && !$self->exists($path)
$type eq "f"
$type eq "d"
!$self->exists($path)
Truth table20%1/5
A or B && not(C)
A= $type eq "f"B= $type eq "d"C= !$self->exists($path)
| |||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||
| 264 | 690 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 265 | 690 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 266 | 690 | my $path = shift; | |||||||||||||||||||||||||||||||||||||
| 267 | 690 | my $type = shift; | |||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||
| 269 | 690 | ▶ | defined $type | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 270 | or croak "Missing required argument 'type'."; | ||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||
| 272 | 690 | ▶ | if ($type eq 'f') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 273 | 230 | my $fulldir = $self->dirname_of_path($self->normalize_real_path($path)); | |||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||
| 275 | 230 | File::Path::mkpath($fulldir, 0); | |||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||
| 277 | 230 | my $abspath = $self->normalize_path($path); | |||||||||||||||||||||||||||||||||||||
| 278 | 230 | my $fullpath = $self->normalize_real_path($path); | |||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||
| 280 | 230 | ▶ | my $fh = FileHandle->new(">$fullpath") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 281 | or croak "Cannot create file $abspath: $!"; | ||||||||||||||||||||||||||||||||||||||
| 282 | 230 | close $fh; | |||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||
| 284 | return bless { | ||||||||||||||||||||||||||||||||||||||
| 285 | fs_root => $self->{fs_root}, | ||||||||||||||||||||||||||||||||||||||
| 286 | 230 | path => $abspath, | |||||||||||||||||||||||||||||||||||||
| 287 | fullpath => $fullpath, | ||||||||||||||||||||||||||||||||||||||
| 288 | }, ref $self; | ||||||||||||||||||||||||||||||||||||||
| 289 | } elsif ($type eq 'd') { | ||||||||||||||||||||||||||||||||||||||
| 290 | 460 | my $abspath = $self->normalize_path($path); | |||||||||||||||||||||||||||||||||||||
| 291 | 460 | my $fullpath = $self->normalize_real_path($path); | |||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||
| 293 | 460 | File::Path::mkpath($fullpath, 0); | |||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||
| 295 | 460 | ▶ | -d $fullpath | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 296 | or croak "Failed to create directory '$abspath'"; | ||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||
| 298 | return bless { | ||||||||||||||||||||||||||||||||||||||
| 299 | fs_root => $self->{fs_root}, | ||||||||||||||||||||||||||||||||||||||
| 300 | 460 | path => $abspath, | |||||||||||||||||||||||||||||||||||||
| 301 | fullpath => $fullpath, | ||||||||||||||||||||||||||||||||||||||
| 302 | }, ref $self; | ||||||||||||||||||||||||||||||||||||||
| 303 | } else { | ||||||||||||||||||||||||||||||||||||||
| 304 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||
| 308 | 496 | ▶ | sub rename { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
rename: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 309 | 496 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 310 | 496 | my $name = shift; | |||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||
| 312 | 496 | ▶ | croak "The 'name' argument must be a plan name, not a path. However, the given value ($name) contains a slash." | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 313 | if $name =~ m#/#; | ||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||
| 315 | 496 | my $abspath = $self->normalize_path($self->dirname.'/'.$name); | |||||||||||||||||||||||||||||||||||||
| 316 | 496 | my $fullpath = $self->normalize_real_path($self->dirname.'/'.$name); | |||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||
| 318 | 496 | rename $self->{fullpath}, $fullpath; | |||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||
| 320 | 496 | $self->{path} = $abspath; | |||||||||||||||||||||||||||||||||||||
| 321 | 496 | $self->{fullpath} = $fullpath; | |||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||
| 323 | 496 | return $self; | |||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||
| 326 | 496 | ▶ | sub move { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
move: called CC=10 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 327 | 496 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 328 | 496 | my $to = shift; | |||||||||||||||||||||||||||||||||||||
| 329 | 496 | ▶ | my $force = shift || 0; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 0
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||
| 331 | 496 | ▶ | UNIVERSAL::isa($to, ref $self) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 332 | or croak "Move failed; the '$to' object is not a '",ref $self,"'"; | ||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||
| 334 | $to->{fs_root} eq $self->{fs_root} | ||||||||||||||||||||||||||||||||||||||
| 335 | 496 | ▶ | or croak "Move failed; the '$to' object belongs to a different root."; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||
| 337 | 496 | ▶ | $to->is_valid | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 338 | or croak "Move failed; the '$to' object is not valid."; | ||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||
| 340 | 496 | ▶ | $to->is_container | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 341 | or croak "Move failed; the '$to' object is not a directory."; | ||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||
| 343 | 496 | ▶ | defined $to->child($self->basename) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 344 | and croak "Move failed; the '$to/",$self->basename,"' object already exists."; | ||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||
| 346 | 496 | ▶ | if ($self->is_container) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 347 | 62 | ▶ | if ($force) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 348 | 62 | $to->create($self->basename, 'd'); | |||||||||||||||||||||||||||||||||||||
| 349 | 62 | ▶ | File::Copy::Recursive::dircopy($self->{fullpath}, $to->{fullpath}.'/'.$self->basename) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 350 | or croak "Move failed; dircopy failure to '$to'"; | ||||||||||||||||||||||||||||||||||||||
| 351 | 62 | File::Path::rmtree($self->{fullpath}); | |||||||||||||||||||||||||||||||||||||
| 352 | } else { | ||||||||||||||||||||||||||||||||||||||
| 353 | 0 | croak "Move failed; cannot move a directory unless the 'force' argument is true."; | |||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||
| 355 | } else { | ||||||||||||||||||||||||||||||||||||||
| 356 | 434 | File::Copy::move($self->{fullpath}, $to->{fullpath}); | |||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||
| 359 | 496 | my $name = $self->basename; | |||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||
| 361 | 496 | $self->{path} = $self->normalize_path($to->path.'/'.$name); | |||||||||||||||||||||||||||||||||||||
| 362 | 496 | $self->{fullpath} = $self->normalize_real_path($to->path.'/'.$name); | |||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||
| 364 | 496 | return $self; | |||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||
| 367 | 248 | ▶ | sub copy { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
copy: called CC=10 SCAR=24.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 368 | 248 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 369 | 248 | my $to = shift; | |||||||||||||||||||||||||||||||||||||
| 370 | 248 | ▶ | my $force = shift || 0; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 0
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||
| 372 | 248 | ▶ | UNIVERSAL::isa($to, ref $self) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 373 | or croak "Copy failed; the '$to' object is not a '",ref $self,"'"; | ||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||
| 375 | $to->{fs_root} eq $self->{fs_root} | ||||||||||||||||||||||||||||||||||||||
| 376 | 248 | ▶ | or croak "Copy failed; the '$to' object belongs to a different root."; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||
| 378 | 248 | ▶ | $to->is_valid | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 379 | or croak "Copy failed; the '$to' object is not valid."; | ||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||
| 381 | 248 | ▶ | $to->is_container | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 382 | or croak "Copy failed; the '$to' object is not a directory."; | ||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||
| 384 | 248 | ▶ | defined $to->child($self->basename, 'd') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 385 | and croak "Copy failed; the '$to/",$self->basename,"' object already exists."; | ||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||
| 387 | 248 | ▶ | if ($self->is_container) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 388 | 31 | ▶ | if ($force) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 389 | 31 | $to->create($self->basename, 'd'); | |||||||||||||||||||||||||||||||||||||
| 390 | 31 | ▶ | File::Copy::Recursive::dircopy($self->{fullpath}, $to->{fullpath}.'/'.$self->basename) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 391 | or croak "Copy failed; dircopy failure to '$to'"; | ||||||||||||||||||||||||||||||||||||||
| 392 | } else { | ||||||||||||||||||||||||||||||||||||||
| 393 | 0 | croak "Copy failed; cannot copy a directory unless the 'force' argument is true."; | |||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||
| 395 | } else { | ||||||||||||||||||||||||||||||||||||||
| 396 | 217 | File::Copy::copy($self->{fullpath}, $to->{fullpath}); | |||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||
| 399 | return bless { | ||||||||||||||||||||||||||||||||||||||
| 400 | fs_root => $self->{fs_root}, | ||||||||||||||||||||||||||||||||||||||
| 401 | 248 | path => $self->normalize_path($to->path.'/'.$self->basename), | |||||||||||||||||||||||||||||||||||||
| 402 | fullpath => $self->normalize_real_path($to->path.'/'.$self->basename), | ||||||||||||||||||||||||||||||||||||||
| 403 | }, ref $self; | ||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||
| 406 | 496 | ▶ | sub remove { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=6 SCAR=20.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 407 | 496 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 408 | 496 | my $force = shift; | |||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||
| 410 | 496 | ▶ | if (-d $self->{fullpath} && $force) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
-d $self->{"fullpath"} and $force
MC/DC50%1/2
-d $self->{"fullpath"} and $force
-d $self->{"fullpath"}
$force
Truth table66%2/3
A and B
A= -d $self->{"fullpath"}B= $force
| |||||||||||||||||||||||||||||||||||||||
| 411 | 279 | File::Path::rmtree($self->{fullpath}); | |||||||||||||||||||||||||||||||||||||
| 412 | ▶ | } elsif (-d $self->{fullpath} && $self->has_children) { | |||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
-d $self->{"fullpath"} and $self->has_children
MC/DC0%0/2
-d $self->{"fullpath"} and $self->has_children
-d $self->{"fullpath"}
$self->has_children
Truth table33%1/3
A and B
A= -d $self->{"fullpath"}B= $self->has_children
| |||||||||||||||||||||||||||||||||||||||
| 413 | 0 | croak "Cannot delete directory with children unless force is true."; | |||||||||||||||||||||||||||||||||||||
| 414 | } elsif (-d $self->{fullpath}) { | ||||||||||||||||||||||||||||||||||||||
| 415 | 0 | rmdir $self->{fullpath}; | |||||||||||||||||||||||||||||||||||||
| 416 | } else { | ||||||||||||||||||||||||||||||||||||||
| 417 | 217 | unlink $self->{fullpath}; | |||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||
| 421 | 224 | ▶ | sub is_readable { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_readable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 422 | 224 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 423 | 224 | return $self->has_content; | |||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||
| 426 | 224 | ▶ | sub is_seekable { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_seekable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 427 | 224 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 428 | # TODO This is naive. Seekability is a little less available than this | ||||||||||||||||||||||||||||||||||||||
| 429 | # would indicate. | ||||||||||||||||||||||||||||||||||||||
| 430 | 224 | return $self->has_content; | |||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||
| 433 | 224 | ▶ | sub is_writable { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_writable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 434 | 224 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 435 | 224 | return $self->has_content; | |||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||
| 438 | 224 | ▶ | sub is_appendable { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_appendable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 439 | 224 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 440 | 224 | return $self->has_content; | |||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||
| 443 | 1568 | ▶ | sub open { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
open: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 444 | 1568 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 445 | 1568 | my $access = shift; | |||||||||||||||||||||||||||||||||||||
| 446 | 1568 | return FileHandle->new($self->{fullpath}, $access) | |||||||||||||||||||||||||||||||||||||
| 447 | or croak "Cannot open $self with access mode '$access': $!"; | ||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||
| 450 | 896 | ▶ | sub content { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
content: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 451 | 896 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||
| 453 | 896 | my $fh = $self->open("r"); | |||||||||||||||||||||||||||||||||||||
| 454 | 896 | my @lines = <$fh>; | |||||||||||||||||||||||||||||||||||||
| 455 | 896 | close $fh; | |||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||
| 457 | 896 | ▶ | return wantarray ? @lines : join '', @lines; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||
| 460 | 119 | ▶ | sub has_children { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
has_children: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 461 | 119 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||
| 463 | opendir DH, $self->{fullpath} | ||||||||||||||||||||||||||||||||||||||
| 464 | 119 | ▶ | or croak "Cannot open directory $self for listing: $!"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 465 | 119 | my @dirs = grep !/^\.\.?$/, readdir DH; | |||||||||||||||||||||||||||||||||||||
| 466 | 119 | closedir DH; | |||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||
| 468 | 119 | ▶ | return @dirs ? 1 : ''; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||
| 471 | 4367 | ▶ | sub children_paths { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
children_paths: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 472 | 4367 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||
| 474 | opendir DH, $self->{fullpath} | ||||||||||||||||||||||||||||||||||||||
| 475 | 4367 | ▶ | or croak "Cannot open directory $self for listing: $!"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 476 | 4367 | my @paths = map { s/^$self->{fs_root}//; $_ } readdir DH; | |||||||||||||||||||||||||||||||||||||
| 477 | 4367 | closedir DH; | |||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||
| 479 | 4367 | return @paths; | |||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||
| 482 | 746 | ▶ | sub children { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
children: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 483 | 746 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||
| 485 | opendir DH, $self->{fullpath} | ||||||||||||||||||||||||||||||||||||||
| 486 | 746 | ▶ | or croak "Cannot open directory $self for listing: $!"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 487 | my @children = map { | ||||||||||||||||||||||||||||||||||||||
| 488 | 746 | ▶ | if (/^\.\.?$/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 489 | () | ||||||||||||||||||||||||||||||||||||||
| 490 | 1492 | } else { | |||||||||||||||||||||||||||||||||||||
| 491 | bless { | ||||||||||||||||||||||||||||||||||||||
| 492 | fs_root => $self->{fs_root}, | ||||||||||||||||||||||||||||||||||||||
| 493 | 990 | path => $self->normalize_path($_), | |||||||||||||||||||||||||||||||||||||
| 494 | fullpath => $self->normalize_real_path($_), | ||||||||||||||||||||||||||||||||||||||
| 495 | }, ref $self; | ||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||
| 497 | } readdir DH; | ||||||||||||||||||||||||||||||||||||||
| 498 | 746 | closedir DH; | |||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||
| 500 | 746 | return @children; | |||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||
| 503 | 788 | ▶ | sub child { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
child: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 504 | 788 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 505 | 788 | my $name = shift; | |||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||
| 507 | 788 | ▶ | croak "Name given, '$name', is a path rather than a name (i.e., it contains a slash)." if $name =~ m#/#; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||
| 509 | 788 | my $abspath = $self->normalize_path($name); | |||||||||||||||||||||||||||||||||||||
| 510 | 788 | my $fullpath = $self->normalize_real_path($name); | |||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||
| 512 | 788 | ▶ | if (-e $fullpath) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 513 | return bless { | ||||||||||||||||||||||||||||||||||||||
| 514 | fs_root => $self->{fs_root}, | ||||||||||||||||||||||||||||||||||||||
| 515 | 42 | path => $abspath, | |||||||||||||||||||||||||||||||||||||
| 516 | fullpath => $fullpath, | ||||||||||||||||||||||||||||||||||||||
| 517 | }, ref $self; | ||||||||||||||||||||||||||||||||||||||
| 518 | } else { | ||||||||||||||||||||||||||||||||||||||
| 519 | 746 | return undef; | |||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||
| 523 | # =item $real_path = $obj->normalize_real_path($messy_path) | ||||||||||||||||||||||||||||||||||||||
| 524 | # | ||||||||||||||||||||||||||||||||||||||
| 525 | # Like C<normalize_path>, except that it returns a real absolute path. | ||||||||||||||||||||||||||||||||||||||
| 526 | # | ||||||||||||||||||||||||||||||||||||||
| 527 | # =cut | ||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||
| 529 | 33609 | ▶ | sub normalize_real_path { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_real_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 530 | 33609 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 531 | 33609 | my $path = shift; | |||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||
| 533 | 33609 | my $abspath = $self->normalize_path($path); | |||||||||||||||||||||||||||||||||||||
| 534 | my $fullpath = File::Spec->canonpath( | ||||||||||||||||||||||||||||||||||||||
| 535 | 33609 | File::Spec->catfile($self->{fs_root}, $abspath) | |||||||||||||||||||||||||||||||||||||
| 536 | ); | ||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||
| 538 | 33609 | return $fullpath; | |||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||
| 541 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||
| 543 | L<File::System>, L<File::System::Object> | ||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||
| 545 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||
| 547 | Andrew Sterling Hanenkamp, E<lt>hanenkamp@users.sourceforge.netE<gt> | ||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||
| 549 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||
| 551 | Copyright 2005 Andrew Sterling Hanenkamp. All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||
| 553 | This software is distributed and licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||
| 555 | =cut | ||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||
| 557 | 7 | 1 | |||||||||||||||||||||||||||||||||||||