line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flower::File; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
598
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
51
|
|
5
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
54
|
|
6
|
2
|
|
|
2
|
|
10
|
use feature qw(say); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
149
|
|
7
|
2
|
|
|
2
|
|
9
|
use Carp qw/confess/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
114
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
10
|
use overload '""' => \&to_string; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
20
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
747
|
use Data::UUID; |
|
2
|
|
|
|
|
681
|
|
|
2
|
|
|
|
|
189
|
|
12
|
2
|
|
|
2
|
|
1891
|
use Number::Format qw/format_bytes/; |
|
2
|
|
|
|
|
18794
|
|
|
2
|
|
|
|
|
1275
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $uuid = Data::UUID->new; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
6
|
|
|
6
|
0
|
2524
|
my $class = shift; |
18
|
6
|
50
|
|
|
|
17
|
confess "called as object method" if ref $class; |
19
|
|
|
|
|
|
|
|
20
|
6
|
|
100
|
|
|
17
|
my $args = shift || {}; |
21
|
|
|
|
|
|
|
|
22
|
6
|
100
|
|
|
|
374
|
confess "no parent supplied" if ( !$args->{parent} ); |
23
|
4
|
100
|
|
|
|
135
|
confess "no filename" if ( !$args->{filename} ); |
24
|
3
|
100
|
|
|
|
132
|
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
|
|
|
280
|
}; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
5
|
bless $self, __PACKAGE__; |
36
|
2
|
|
|
|
|
6
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new_from_local_file { |
40
|
1
|
|
|
1
|
0
|
1084
|
my $class = shift; |
41
|
1
|
|
|
|
|
2
|
my $args = shift; |
42
|
|
|
|
|
|
|
|
43
|
1
|
50
|
|
|
|
5
|
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
|
|
|
|
3
|
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
|
|
|
|
|
31
|
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
|
544
|
my $self = shift; |
69
|
7
|
50
|
|
|
|
17
|
confess "size requested on file with no size" unless defined $self->{size}; |
70
|
7
|
|
|
|
|
25
|
return $self->{size}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub uuid { |
74
|
5
|
|
|
5
|
0
|
7
|
my $self = shift; |
75
|
5
|
|
|
|
|
21
|
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
|
|
|
|
|
12
|
return format_bytes( $self->size ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub nice_filename { |
96
|
5
|
|
|
5
|
0
|
6
|
my $self = shift; |
97
|
5
|
|
|
|
|
14
|
return $self->{filename}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub to_string { |
101
|
5
|
|
|
5
|
0
|
2077
|
my $self = shift; |
102
|
|
|
|
|
|
|
return |
103
|
5
|
|
|
|
|
10
|
$self->uuid . " - " |
104
|
|
|
|
|
|
|
. $self->nice_filename . " (" |
105
|
|
|
|
|
|
|
. $self->nice_size |
106
|
|
|
|
|
|
|
. " bytes)"; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |