line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Stat::OO; |
2
|
2
|
|
|
2
|
|
55616
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
3
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
73
|
|
4
|
2
|
|
|
2
|
|
9
|
use base qw(Class::Accessor); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
11956
|
|
5
|
2
|
|
|
2
|
|
11867
|
use DateTime; |
|
2
|
|
|
|
|
453170
|
|
|
2
|
|
|
|
|
867
|
|
6
|
|
|
|
|
|
|
our @stat_keys = |
7
|
|
|
|
|
|
|
qw(dev ino mode nlink uid gid rdev size atime mtime ctime blksize blocks); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
File::Stat::OO->mk_accessors(qw(file use_datetime), @stat_keys); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
File::Stat::OO - OO interface for accessing file status attributes |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.03 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use File::Stat::OO; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $foo = File::Stat::OO->new({file => '/etc/password'}); |
28
|
|
|
|
|
|
|
$foo->stat; # stat file specified at instantiation time |
29
|
|
|
|
|
|
|
print $foo->size; |
30
|
|
|
|
|
|
|
print $foo->mtime; # modification time in epoch seconds |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
or inflate epoch seconds into DateTime objects |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $foo = File::Stat::OO->new(); |
35
|
|
|
|
|
|
|
$foo->use_datetime(1); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Or the two lines above can be combined as |
38
|
|
|
|
|
|
|
# my $foo = File::Stat::OO->new({use_datetime => 1}); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$foo->stat('/etc/password'); # pass file name to the stat method |
41
|
|
|
|
|
|
|
print $foo->mtime; # returns DateTime object not an epoch |
42
|
|
|
|
|
|
|
print $foo->mtime->epoch; # epoch seconds |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 METHODS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 stat |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Generate stat information. Takes an optional filename parameter |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub stat { |
53
|
2
|
|
|
2
|
1
|
7808
|
my $self = shift; |
54
|
2
|
50
|
|
|
|
17
|
$self->file($_[0]) if ($_[0]); |
55
|
2
|
50
|
|
|
|
39
|
die "No such file: " . $self->file unless -e $self->file; |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
77
|
my @file_stat = stat($self->file); |
58
|
2
|
|
|
|
|
50
|
my $counter = 0; |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
6
|
foreach my $stat (@stat_keys) { |
61
|
26
|
100
|
100
|
|
|
50240
|
if ($stat =~ /^[a|m|c]time$/ && $self->use_datetime) { |
62
|
3
|
|
|
|
|
65
|
$self->$stat( |
63
|
|
|
|
|
|
|
DateTime->from_epoch( |
64
|
|
|
|
|
|
|
epoch => $file_stat[$counter++], |
65
|
|
|
|
|
|
|
time_zone => 'local' |
66
|
|
|
|
|
|
|
) |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
} else { |
69
|
23
|
|
|
|
|
122
|
$self->$stat($file_stat[$counter++]); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub owner { |
75
|
1
|
|
|
1
|
1
|
2780
|
my $self = shift; |
76
|
1
|
|
|
|
|
6
|
return (getpwuid($self->uid))[0]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub group { |
80
|
1
|
|
|
1
|
1
|
4382
|
my $self = shift; |
81
|
1
|
|
|
|
|
13
|
return (getgrgid($self->gid))[0]; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 use_datetime |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
If set, invocations of stat will record times as DateTime objects rather than |
87
|
|
|
|
|
|
|
epoch seconds |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 dev |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
device number of filesystem |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 ino |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
inode number |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 mode |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
file mode type and permissions |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 nlink |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
number of (hard) links to the file |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 uid |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
numeric user ID of the file's owner |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 owner |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
name of the file owner |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 gid |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
numeric group ID of the file's owner |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 group |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
group name of the file's owner |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 rdev |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
the device identifier (special files only) |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 size |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
size of the file in bytes |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 atime |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
last access time (DateTime object) |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 mtime |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
last modify time (DateTime object) |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 ctime |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
inode chane time (DateTime object) |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 blksize |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
preferred blocksize for file system I/O |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 blocks |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
actual number of blocks allocated |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 AUTHOR |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Dan Horne, C<< <dhorne at cpan.org> >> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 BUGS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
156
|
|
|
|
|
|
|
C<bug-file-stat-oo at rt.cpan.org>, or through the web interface at |
157
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Stat-OO>. |
158
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
159
|
|
|
|
|
|
|
your bug as I make changes. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SUPPORT |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
perldoc File::Stat::OO |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
You can also look for information at: |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over 4 |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
L<http://annocpan.org/dist/File-Stat-OO> |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item * CPAN Ratings |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/File-Stat-OO> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=File-Stat-OO> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item * Search CPAN |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/File-Stat-OO> |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=back |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 SEE ALSO |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
C<File::stat> - File::Stat::OO provides additonal functionality such as: |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
* Optionally returning the atime, ctime and mtime values as DateTime |
194
|
|
|
|
|
|
|
objects instead of epoch seconds |
195
|
|
|
|
|
|
|
* Providing the name and owner of the file in addition to the uid |
196
|
|
|
|
|
|
|
and gid |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Copyright 2008 Dan Horne, all rights reserved. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
203
|
|
|
|
|
|
|
under the same terms as Perl itself. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
1; # End of File::Stat::OO |