line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flower::File; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
585
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
48
|
|
5
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
54
|
|
6
|
2
|
|
|
2
|
|
9
|
use feature qw(say); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
160
|
|
7
|
2
|
|
|
2
|
|
9
|
use Carp qw/confess/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
117
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
9
|
use overload '""' => \&to_string; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
20
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
828
|
use Data::UUID; |
|
2
|
|
|
|
|
716
|
|
|
2
|
|
|
|
|
124
|
|
12
|
2
|
|
|
2
|
|
1809
|
use Number::Format qw/format_bytes/; |
|
2
|
|
|
|
|
18878
|
|
|
2
|
|
|
|
|
1368
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $uuid = Data::UUID->new; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
6
|
|
|
6
|
0
|
1650
|
my $class = shift; |
18
|
6
|
50
|
|
|
|
16
|
confess "called as object method" if ref $class; |
19
|
|
|
|
|
|
|
|
20
|
6
|
|
100
|
|
|
19
|
my $args = shift || {}; |
21
|
|
|
|
|
|
|
|
22
|
6
|
100
|
|
|
|
374
|
confess "no parent supplied" if ( !$args->{parent} ); |
23
|
4
|
100
|
|
|
|
128
|
confess "no filename" if ( !$args->{filename} ); |
24
|
3
|
100
|
|
|
|
126
|
confess "no size" if ( !$args->{size} ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $self = { |
27
|
|
|
|
|
|
|
uuid => $args->{uuid} || $uuid->create_str, |
28
|
|
|
|
|
|
|
filename => $args->{filename}, |
29
|
|
|
|
|
|
|
parent => $args->{parent}, |
30
|
|
|
|
|
|
|
size => $args->{size}, |
31
|
|
|
|
|
|
|
path => $args->{path}, |
32
|
|
|
|
|
|
|
mtime => $args->{mtime}, |
33
|
2
|
|
33
|
|
|
209
|
}; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
6
|
bless $self, __PACKAGE__; |
36
|
2
|
|
|
|
|
6
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new_from_local_file { |
40
|
1
|
|
|
1
|
0
|
1067
|
my $class = shift; |
41
|
1
|
|
|
|
|
2
|
my $args = shift; |
42
|
|
|
|
|
|
|
|
43
|
1
|
50
|
|
|
|
4
|
confess "called as object method" if ref $class; |
44
|
1
|
50
|
|
|
|
4
|
confess "no filename" unless $args->{filename}; |
45
|
1
|
50
|
|
|
|
16
|
confess "'$args->{filename}' does not exist" unless -f $args->{filename}; |
46
|
1
|
50
|
|
|
|
4
|
confess "no parent" unless $args->{parent}; |
47
|
1
|
50
|
|
|
|
3
|
confess "no path" unless $args->{path}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $file_obj = __PACKAGE__->new( |
50
|
|
|
|
|
|
|
{ filename => $args->{filename}, |
51
|
|
|
|
|
|
|
path => $args->{path}, |
52
|
|
|
|
|
|
|
size => -s $args->{filename}, |
53
|
|
|
|
|
|
|
parent => $args->{parent}, |
54
|
1
|
|
|
|
|
30
|
mtime => ( stat( $args->{filename} ) )[9], |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
); |
57
|
1
|
|
|
|
|
4
|
return $file_obj; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# accessor |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub filename { |
63
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
64
|
0
|
|
|
|
|
0
|
return $self->{filename}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub size { |
68
|
7
|
|
|
7
|
0
|
428
|
my $self = shift; |
69
|
7
|
50
|
|
|
|
17
|
confess "size requested on file with no size" unless defined $self->{size}; |
70
|
7
|
|
|
|
|
23
|
return $self->{size}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub uuid { |
74
|
5
|
|
|
5
|
0
|
7
|
my $self = shift; |
75
|
5
|
|
|
|
|
18
|
return $self->{uuid}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub path { |
79
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
80
|
0
|
|
|
|
|
0
|
return $self->{path}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub mtime { |
84
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
85
|
0
|
|
|
|
|
0
|
return $self->{mtime}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# helper |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub nice_size { |
91
|
6
|
|
|
6
|
0
|
8
|
my $self = shift; |
92
|
6
|
|
|
|
|
11
|
return format_bytes( $self->size ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub nice_filename { |
96
|
5
|
|
|
5
|
0
|
9
|
my $self = shift; |
97
|
5
|
|
|
|
|
16
|
return $self->{filename}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub to_string { |
101
|
5
|
|
|
5
|
0
|
1737
|
my $self = shift; |
102
|
|
|
|
|
|
|
return |
103
|
5
|
|
|
|
|
12
|
$self->uuid . " - " |
104
|
|
|
|
|
|
|
. $self->nice_filename . " (" |
105
|
|
|
|
|
|
|
. $self->nice_size |
106
|
|
|
|
|
|
|
. " bytes)"; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |