line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Path::Classy::Entity; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
16
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
70
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.002_0'; |
9
|
|
|
|
|
|
|
our @ISA; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
1
|
|
|
1
|
|
6
|
require Path::Class::Entity; |
13
|
1
|
|
|
|
|
46
|
@ISA = qw(Path::Class::Entity); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
1030
|
use Attribute::Memoize; # XXX Memoize::Attrs |
|
1
|
|
|
|
|
16953
|
|
|
1
|
|
|
|
|
63
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _size_formatter :Memoize { |
19
|
0
|
|
|
0
|
|
0
|
require Number::Bytes::Human; |
20
|
0
|
|
|
|
|
0
|
return Number::Bytes::Human->new; |
21
|
1
|
|
|
1
|
|
9
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _format_size { |
24
|
0
|
|
|
0
|
|
|
my ($sz, $opt) = @_; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $format = $opt->{format}; |
27
|
0
|
0
|
|
|
|
|
if ( $format eq 'h' ) { |
|
|
0
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
return _size_formatter->format( $sz ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif ( !$format ) { # raw bytes (equiv to no format) |
31
|
0
|
|
|
|
|
|
return $sz; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
0
|
|
|
|
|
|
die "unknown format '$format'"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# -s |
39
|
|
|
|
|
|
|
sub size { |
40
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
41
|
0
|
|
|
|
|
|
my $raw_size = -s $self; |
42
|
0
|
0
|
|
|
|
|
if ( @_ ) { |
43
|
0
|
|
|
|
|
|
return _format_size( $raw_size, @_ ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else { |
46
|
0
|
|
|
|
|
|
return $raw_size; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# -z |
51
|
0
|
|
|
0
|
0
|
|
sub is_empty { -z shift } |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# -e |
54
|
0
|
|
|
0
|
0
|
|
sub exists { -e shift; } |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _format_mode { |
57
|
0
|
|
|
0
|
|
|
my ($mode, $opt) = @_; |
58
|
0
|
|
|
|
|
|
my $format = $opt->{format}; |
59
|
0
|
0
|
|
|
|
|
if ( !$format ) { |
|
|
0
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return $mode; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
elsif ( $format eq 'oct' ) { |
63
|
0
|
|
|
|
|
|
return sprintf '%04o', $mode; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
# TODO: 'ls' |
66
|
|
|
|
|
|
|
else { |
67
|
0
|
|
|
|
|
|
die "unknown mode format '$format'"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# $f->mode |
72
|
|
|
|
|
|
|
# $f->mode({ format => '' }) |
73
|
|
|
|
|
|
|
# $f->mode({ format => 'ls' }) |
74
|
|
|
|
|
|
|
# $f->mode({ format => 'oct' }) |
75
|
|
|
|
|
|
|
sub mode { |
76
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
77
|
0
|
|
|
|
|
|
my $raw_mode = $self->stat->mode & 07777; # perldoc -f stat |
78
|
0
|
0
|
|
|
|
|
if ( @_ ) { |
79
|
0
|
|
|
|
|
|
return _format_mode( $raw_mode, @_ ); |
80
|
|
|
|
|
|
|
} else { |
81
|
0
|
|
|
|
|
|
return $raw_mode; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _dt_from_epoch { |
86
|
0
|
|
|
0
|
|
|
require DateTime; |
87
|
0
|
|
|
|
|
|
return DateTime->from_epoch( epoch => shift ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
1
|
|
646
|
use constant SECS_IN_A_DAY => 60*60*24*1.00; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
562
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _format_from_epoch { |
93
|
0
|
|
|
0
|
|
|
my $sec = shift; |
94
|
0
|
|
|
|
|
|
my $opt = shift; |
95
|
0
|
|
0
|
|
|
|
my $as = $opt->{as} || 'sec'; |
96
|
0
|
0
|
|
|
|
|
if ( $as eq 'sec' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# already in seconds |
98
|
0
|
|
|
|
|
|
return $sec; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
elsif ( $as eq 'days' ) { |
101
|
0
|
|
|
|
|
|
return $sec / SECS_IN_A_DAY; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
elsif ( $as eq 'dt' ) { |
104
|
|
|
|
|
|
|
# return a DateTime |
105
|
0
|
|
|
|
|
|
return _dt_from_epoch( $sec ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
else { |
108
|
0
|
|
|
|
|
|
die "unknown time type '$as'"; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _format_from_start { |
113
|
0
|
|
|
0
|
|
|
my $days = shift; |
114
|
0
|
|
|
|
|
|
my $opt = shift; |
115
|
0
|
|
0
|
|
|
|
my $as = $opt->{as} || 'sec'; |
116
|
0
|
0
|
|
|
|
|
if ( $as eq 'days' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# already in days |
118
|
0
|
|
|
|
|
|
return $days; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
elsif ( $as eq 'sec' ) { |
121
|
0
|
|
|
|
|
|
return $days * SECS_IN_A_DAY; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
elsif ( $as eq 'dt' ) { |
124
|
0
|
|
|
|
|
|
return _dt_from_epoch( $^T + $days * SECS_IN_A_DAY ); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
else { |
127
|
0
|
|
|
|
|
|
die "unknown time type '$as'"; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# $f->mtime |
134
|
|
|
|
|
|
|
# $f->mtime({ from => 'epoch' }) |
135
|
|
|
|
|
|
|
# $f->mtime({ from => 'start', as => 'days' }); # -M $f |
136
|
|
|
|
|
|
|
# $f->mtime({ as => 'dt' }); |
137
|
|
|
|
|
|
|
sub mtime { |
138
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
139
|
0
|
0
|
|
|
|
|
if ( @_ ) { |
140
|
0
|
|
|
|
|
|
my $opt = shift; |
141
|
0
|
|
0
|
|
|
|
my $from = $opt->{from} || 'epoch'; |
142
|
0
|
0
|
|
|
|
|
if ( $from eq 'epoch' ) { |
|
|
0
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
return _format_from_epoch( $self->stat->mtime, $opt ); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
elsif ( $from eq 'start' ) { |
146
|
0
|
|
|
|
|
|
return _format_from_start( -( -M $self ), $opt ); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
else { |
149
|
0
|
|
|
|
|
|
die "unknown time ref '$from'"; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} else { |
152
|
0
|
|
|
|
|
|
return $self->stat->mtime; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# -A |
157
|
|
|
|
|
|
|
sub atime { |
158
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
159
|
0
|
0
|
|
|
|
|
if ( @_ ) { |
160
|
0
|
|
|
|
|
|
my $opt = shift; |
161
|
0
|
|
0
|
|
|
|
my $from = $opt->{from} || 'epoch'; |
162
|
0
|
0
|
|
|
|
|
if ( $from eq 'epoch' ) { |
|
|
0
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
return _format_from_epoch( $self->stat->atime, $opt ); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
elsif ( $from eq 'start' ) { |
166
|
0
|
|
|
|
|
|
return _format_from_start( -A $self, $opt ); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
else { |
169
|
0
|
|
|
|
|
|
die "unknown time ref '$from'"; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} else { |
172
|
0
|
|
|
|
|
|
return $self->stat->atime; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# -C |
177
|
|
|
|
|
|
|
sub ctime { |
178
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
179
|
0
|
0
|
|
|
|
|
if ( @_ ) { |
180
|
0
|
|
|
|
|
|
my $opt = shift; |
181
|
0
|
|
0
|
|
|
|
my $from = $opt->{from} || 'epoch'; |
182
|
0
|
0
|
|
|
|
|
if ( $from eq 'epoch' ) { |
|
|
0
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
return _format_from_epoch( $self->stat->ctime, $opt ); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
elsif ( $from eq 'start' ) { |
186
|
0
|
|
|
|
|
|
return _format_from_start( -C $self, $opt ); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
else { |
189
|
0
|
|
|
|
|
|
die "unknown time ref '$from'"; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} else { |
192
|
0
|
|
|
|
|
|
return $self->stat->ctime; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
# (-r, -R) (-w, -W) (-x, -X) (-o, -O) |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
1; |