line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#======================================================================== |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Badger::Filesystem::File |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION |
6
|
|
|
|
|
|
|
# OO representation of a file in a filesystem. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# AUTHOR |
9
|
|
|
|
|
|
|
# Andy Wardley |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
#======================================================================== |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Badger::Filesystem::File; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Badger::Class |
16
|
70
|
|
|
|
|
567
|
version => 0.01, |
17
|
|
|
|
|
|
|
base => 'Badger::Filesystem::Path', |
18
|
|
|
|
|
|
|
debug => 0, |
19
|
|
|
|
|
|
|
dumps => 'path volume directory name stats', |
20
|
|
|
|
|
|
|
import => 'class', |
21
|
|
|
|
|
|
|
constants => 'ARRAY BLANK', |
22
|
|
|
|
|
|
|
constant => { |
23
|
|
|
|
|
|
|
type => 'File', |
24
|
|
|
|
|
|
|
is_file => 1, |
25
|
70
|
|
|
70
|
|
482
|
}; |
|
70
|
|
|
|
|
146
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# aliases |
29
|
|
|
|
|
|
|
*base = \&directory; |
30
|
|
|
|
|
|
|
*copy = \©_to; |
31
|
|
|
|
|
|
|
*move = \&move_to; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub init { |
35
|
295
|
|
|
295
|
1
|
508
|
my ($self, $config) = @_; |
36
|
295
|
|
|
|
|
760
|
$self->init_path($config); |
37
|
295
|
|
|
|
|
821
|
$self->init_options($config); |
38
|
295
|
|
|
|
|
1094
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub directory { |
42
|
5
|
|
|
5
|
1
|
9
|
my $self = shift; |
43
|
|
|
|
|
|
|
return @_ |
44
|
5
|
50
|
|
|
|
26
|
? $self->filesystem->directory( $self->relative(@_) ) |
45
|
|
|
|
|
|
|
: $self->parent; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub file { |
49
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
50
|
|
|
|
|
|
|
return @_ |
51
|
0
|
0
|
|
|
|
0
|
? $self->filesystem->file( $self->relative(@_) ) |
52
|
|
|
|
|
|
|
: $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub exists { |
56
|
74
|
|
|
74
|
1
|
209
|
my $self = shift; |
57
|
|
|
|
|
|
|
# cache the stats returned in case we want them later |
58
|
74
|
|
|
|
|
162
|
return ($self->{ stats } = $self->filesystem->file_exists($self->{ path })); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub create { |
62
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
63
|
2
|
|
|
|
|
8
|
$self->filesystem->create_file($self->{ path }, @_); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub touch { |
67
|
2
|
|
|
2
|
1
|
7
|
my $self = shift; |
68
|
2
|
|
|
|
|
9
|
$self->filesystem->touch_file($self->{ path }); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub open { |
72
|
3
|
|
|
3
|
1
|
20
|
my $self = shift; |
73
|
3
|
|
|
|
|
11
|
$self->filesystem->open_file($self->{ path }, @_, $self->{ options }); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub read { |
77
|
29
|
|
|
29
|
1
|
57
|
my $self = shift; |
78
|
29
|
|
|
|
|
80
|
$self->filesystem->read_file($self->{ path }, @_, $self->{ options }); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub write { |
82
|
12
|
|
|
12
|
1
|
92
|
my $self = shift; |
83
|
12
|
|
|
|
|
39
|
$self->filesystem->write_file($self->{ path }, @_, $self->{ options }); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub append { |
87
|
4
|
|
|
4
|
1
|
8
|
my $self = shift; |
88
|
4
|
|
|
|
|
14
|
$self->filesystem->append_file($self->{ path }, @_, $self->{ options }); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub copy_to { |
92
|
2
|
|
|
2
|
1
|
7
|
my $self = shift; |
93
|
2
|
|
|
|
|
6
|
$self->filesystem->copy_file($self->{ path }, @_); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub copy_from { |
97
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
98
|
1
|
|
|
|
|
4
|
$self->filesystem->copy_file(shift, $self->{ path }, @_); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub move_to { |
102
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
103
|
1
|
|
|
|
|
3
|
$self->filesystem->move_file($self->{ path }, @_); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub move_from { |
107
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
108
|
0
|
|
|
|
|
0
|
$self->filesystem->move_file(shift, $self->{ path }, @_); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub print { |
112
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
113
|
2
|
|
|
|
|
11
|
$self->write( join(BLANK, @_) ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub delete { |
117
|
13
|
|
|
13
|
1
|
93
|
my $self = shift; |
118
|
13
|
|
|
|
|
43
|
$self->filesystem->delete_file($self->{ path }, @_); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub text { |
122
|
18
|
|
|
18
|
1
|
120
|
my $self = shift; |
123
|
18
|
|
|
|
|
54
|
my $text = $self->read(@_, $self->{ options }); |
124
|
18
|
|
|
|
|
143
|
return $text; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub data { |
128
|
11
|
|
|
11
|
1
|
51
|
my $self = shift; |
129
|
11
|
|
|
|
|
23
|
my $codec = $self->{ options }->{ codec }; |
130
|
11
|
|
|
|
|
16
|
my $data; |
131
|
|
|
|
|
|
|
|
132
|
11
|
|
|
|
|
11
|
$self->debug("filesystem codec: $codec") if DEBUG; |
133
|
|
|
|
|
|
|
|
134
|
11
|
100
|
|
|
|
39
|
if (@_) { |
135
|
5
|
50
|
|
|
|
14
|
$data = @_ == 1 ? shift : [@_]; |
136
|
5
|
50
|
|
|
|
19
|
$data = $codec->encode($data) if $codec; |
137
|
5
|
|
|
|
|
397
|
return $self->write($data); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
else { |
140
|
6
|
|
|
|
|
19
|
$data = $self->read; |
141
|
6
|
50
|
|
|
|
44
|
$data = $codec->decode($data) if $codec; |
142
|
6
|
|
|
|
|
125
|
return $data; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub accept { |
147
|
196
|
|
|
196
|
1
|
386
|
$_[1]->visit_file($_[0]); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
class->methods( |
151
|
|
|
|
|
|
|
map { |
152
|
|
|
|
|
|
|
my $item = $_; # lexical copy for closure |
153
|
|
|
|
|
|
|
$item => sub { |
154
|
2
|
|
|
2
|
|
8
|
my $self = shift; |
155
|
|
|
|
|
|
|
# ...and strict in what you provide |
156
|
2
|
|
|
|
|
12
|
$self->encoding(':' . $item); |
157
|
2
|
|
|
|
|
6
|
return $self; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
qw( raw utf8 crlf bytes ) |
161
|
|
|
|
|
|
|
); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__END__ |