line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Followme::FolderData; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
980
|
use 5.008005; |
|
18
|
|
|
|
|
89
|
|
4
|
18
|
|
|
18
|
|
107
|
use strict; |
|
18
|
|
|
|
|
42
|
|
|
18
|
|
|
|
|
436
|
|
5
|
18
|
|
|
18
|
|
91
|
use warnings; |
|
18
|
|
|
|
|
58
|
|
|
18
|
|
|
|
|
553
|
|
6
|
18
|
|
|
18
|
|
115
|
use integer; |
|
18
|
|
|
|
|
48
|
|
|
18
|
|
|
|
|
101
|
|
7
|
18
|
|
|
18
|
|
536
|
use lib '../..'; |
|
18
|
|
|
|
|
43
|
|
|
18
|
|
|
|
|
116
|
|
8
|
|
|
|
|
|
|
|
9
|
18
|
|
|
18
|
|
2472
|
use File::Spec::Functions qw(abs2rel catfile rel2abs splitdir); |
|
18
|
|
|
|
|
44
|
|
|
18
|
|
|
|
|
1181
|
|
10
|
|
|
|
|
|
|
|
11
|
18
|
|
|
18
|
|
115
|
use base qw(App::Followme::BaseData); |
|
18
|
|
|
|
|
48
|
|
|
18
|
|
|
|
|
8549
|
|
12
|
18
|
|
|
18
|
|
150
|
use App::Followme::FIO; |
|
18
|
|
|
|
|
43
|
|
|
18
|
|
|
|
|
68994
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = "2.02"; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
# Read the default parameter values |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub parameters { |
20
|
364
|
|
|
364
|
1
|
611
|
my ($self) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
return ( |
23
|
364
|
|
|
|
|
2256
|
extension => '', |
24
|
|
|
|
|
|
|
site_url => '', |
25
|
|
|
|
|
|
|
remote_url => '', |
26
|
|
|
|
|
|
|
author => '', |
27
|
|
|
|
|
|
|
size_format => 'kb', |
28
|
|
|
|
|
|
|
date_format => 'Mon d, yyyy h:mm', |
29
|
|
|
|
|
|
|
exclude_index => 0, |
30
|
|
|
|
|
|
|
exclude => '', |
31
|
|
|
|
|
|
|
exclude_dirs => '.*,_*', |
32
|
|
|
|
|
|
|
web_extension => 'html', |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
37
|
|
|
|
|
|
|
# Return the author's name stored in theconfiguration file |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub calculate_author { |
40
|
14
|
|
|
14
|
0
|
715
|
my ($self, $filename) = @_; |
41
|
14
|
|
|
|
|
45
|
return $self->{author}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
45
|
|
|
|
|
|
|
# Calculate the creation date from the modification date |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub calculate_date { |
48
|
5
|
|
|
5
|
0
|
650
|
my ($self, $filename) = @_; |
49
|
5
|
|
|
|
|
15
|
return $self->get_mdate($filename); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
53
|
|
|
|
|
|
|
# Get the list of keywords from the file path |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub calculate_keywords { |
56
|
8
|
|
|
8
|
0
|
679
|
my ($self, $filename) = @_; |
57
|
8
|
|
|
|
|
28
|
$filename = $self->dir_to_filename($filename); |
58
|
|
|
|
|
|
|
|
59
|
8
|
|
|
|
|
43
|
$filename = abs2rel($filename); |
60
|
8
|
|
|
|
|
729
|
my @path = splitdir($filename); |
61
|
8
|
|
|
|
|
48
|
pop(@path); |
62
|
|
|
|
|
|
|
|
63
|
8
|
|
100
|
|
|
37
|
my $keywords = pop(@path) || ''; |
64
|
8
|
|
|
|
|
26
|
return $keywords; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
68
|
|
|
|
|
|
|
# Calculate the title from the filename root |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub calculate_title { |
71
|
32
|
|
|
32
|
0
|
841
|
my ($self, $filename) = @_; |
72
|
32
|
|
|
|
|
150
|
$filename = $self->dir_to_filename($filename); |
73
|
|
|
|
|
|
|
|
74
|
32
|
|
|
|
|
131
|
my ($dir, $file) = fio_split_filename($filename); |
75
|
32
|
|
|
|
|
117
|
my ($root, $ext) = split(/\./, $file); |
76
|
|
|
|
|
|
|
|
77
|
32
|
100
|
|
|
|
110
|
if ($root eq 'index') { |
78
|
10
|
|
|
|
|
34
|
my @dirs = splitdir($dir); |
79
|
10
|
|
50
|
|
|
76
|
$root = pop(@dirs) || ''; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
32
|
50
|
|
|
|
185
|
$root =~ s/^\d+// unless $root =~ /^\d+$/; |
83
|
32
|
|
|
|
|
110
|
my @words = map {ucfirst $_} split(/\-/, $root); |
|
32
|
|
|
|
|
138
|
|
84
|
|
|
|
|
|
|
|
85
|
32
|
|
|
|
|
142
|
return join(' ', @words); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
89
|
|
|
|
|
|
|
# Check that filename is defined, die if not |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub check_filename { |
92
|
610
|
|
|
610
|
0
|
1195
|
my ($self, $name, $filename) = @_; |
93
|
|
|
|
|
|
|
|
94
|
610
|
50
|
|
|
|
1375
|
die "Cannot use \$$name outside of loop" unless defined $filename; |
95
|
610
|
|
|
|
|
1161
|
return; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
99
|
|
|
|
|
|
|
# Get the name of the web file a file will be converted to |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub convert_filename { |
102
|
12
|
|
|
12
|
0
|
39
|
my ($self, $filename) = @_; |
103
|
|
|
|
|
|
|
|
104
|
12
|
|
|
|
|
122
|
$filename =~ s/\.[^\.]*$/.$self->{web_extension}/; |
105
|
12
|
|
|
|
|
43
|
return $filename; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
109
|
|
|
|
|
|
|
# Get the name of the source directory for ConvertPage |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub convert_source_directory { |
112
|
9
|
|
|
9
|
0
|
25
|
my ($self, $directory) = @_; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Defaults to same as output directory |
115
|
9
|
|
|
|
|
23
|
return $directory; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
119
|
|
|
|
|
|
|
# Get a filename if the directory happens to be a directory |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub dir_to_filename { |
122
|
216
|
|
|
216
|
0
|
2211
|
my ($self, $directory) = @_; |
123
|
|
|
|
|
|
|
|
124
|
216
|
|
|
|
|
324
|
my $filename; |
125
|
216
|
100
|
|
|
|
3712
|
if (-d $directory) { |
126
|
15
|
|
|
|
|
67
|
my $index = 'index.' . $self->{web_extension}; |
127
|
15
|
|
|
|
|
103
|
$filename = catfile($directory, $index); |
128
|
|
|
|
|
|
|
} else { |
129
|
201
|
|
|
|
|
555
|
$filename = $directory; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
216
|
|
|
|
|
566
|
return $filename; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
136
|
|
|
|
|
|
|
# Fetch data from all its possible sources |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub fetch_data { |
139
|
39
|
|
|
39
|
0
|
87
|
my ($self, $name, $filename, $loop) = @_; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Look under both sets of functions |
142
|
|
|
|
|
|
|
|
143
|
39
|
|
|
|
|
108
|
$self->check_filename($name, $filename); |
144
|
39
|
|
|
|
|
107
|
my %data = $self->gather_data('get', $name, $filename, $loop); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
%data = (%data, $self->gather_data('calculate', $name, $filename, $loop)) |
147
|
39
|
100
|
|
|
|
112
|
unless exists $data{$name}; |
148
|
|
|
|
|
|
|
|
149
|
39
|
|
|
|
|
109
|
return %data; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
153
|
|
|
|
|
|
|
# Convert filename to url |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub filename_to_url { |
156
|
103
|
|
|
103
|
0
|
281
|
my ($self, $directory, $filename, $ext) = @_; |
157
|
|
|
|
|
|
|
|
158
|
103
|
|
|
|
|
229
|
$filename = $self->dir_to_filename($filename); |
159
|
|
|
|
|
|
|
|
160
|
103
|
|
|
|
|
374
|
$filename = rel2abs($filename); |
161
|
103
|
|
|
|
|
1476
|
$filename = abs2rel($filename, $directory); |
162
|
|
|
|
|
|
|
|
163
|
103
|
50
|
|
|
|
6216
|
my @path = $filename eq '.' ? () : splitdir($filename); |
164
|
|
|
|
|
|
|
|
165
|
103
|
|
|
|
|
574
|
my $url = join('/', @path); |
166
|
103
|
100
|
|
|
|
674
|
$url =~ s/\.[^\.]*$/.$ext/ if defined $ext; |
167
|
|
|
|
|
|
|
|
168
|
103
|
|
|
|
|
419
|
return $url; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
172
|
|
|
|
|
|
|
# Find the filename at an offset to the current filename |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub find_filename { |
175
|
10
|
|
|
10
|
0
|
17
|
my ($self, $offset, $filename, $loop) = @_; |
176
|
10
|
50
|
|
|
|
21
|
die "Can't use \$url_* outside of for\n" unless $loop; |
177
|
|
|
|
|
|
|
|
178
|
10
|
|
|
|
|
14
|
my $match = -999; |
179
|
10
|
|
|
|
|
26
|
foreach my $i (0 .. @$loop) { |
180
|
30
|
100
|
|
|
|
56
|
if ($loop->[$i] eq $filename) { |
181
|
10
|
|
|
|
|
15
|
$match = $i; |
182
|
10
|
|
|
|
|
14
|
last; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
10
|
|
|
|
|
16
|
my $index = $match + $offset; |
187
|
10
|
100
|
100
|
|
|
51
|
if ($index < 0 || $index > @$loop-1) { |
188
|
2
|
|
|
|
|
5
|
$filename = ''; |
189
|
|
|
|
|
|
|
} else { |
190
|
8
|
|
|
|
|
15
|
$filename = $loop->[$index]; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
10
|
|
|
|
|
31
|
return $filename; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
197
|
|
|
|
|
|
|
# Build a recursive list of directories with a breadth first search |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub find_matching_directories { |
200
|
41
|
|
|
41
|
0
|
96
|
my ($self, $directory) = @_; |
201
|
|
|
|
|
|
|
|
202
|
41
|
|
|
|
|
110
|
my ($filenames, $subdirectories) = fio_visit($directory); |
203
|
|
|
|
|
|
|
|
204
|
41
|
|
|
|
|
859
|
my @directories; |
205
|
41
|
|
|
|
|
116
|
foreach my $subdirectory (@$subdirectories) { |
206
|
16
|
50
|
|
|
|
56
|
next unless $self->match_directory($subdirectory); |
207
|
16
|
|
|
|
|
48
|
push(@directories, $subdirectory); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
41
|
|
|
|
|
72
|
foreach my $subdirectory (@directories) { |
211
|
16
|
|
|
|
|
57
|
push(@directories, $self->find_matching_directories($subdirectory)); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
41
|
|
|
|
|
145
|
return @directories; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
218
|
|
|
|
|
|
|
# Build a list of matching files in a folder |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub find_matching_files { |
221
|
88
|
|
|
88
|
0
|
200
|
my ($self, $folder) = @_; |
222
|
|
|
|
|
|
|
|
223
|
88
|
|
|
|
|
255
|
my ($filenames, $folders) = fio_visit($folder); |
224
|
|
|
|
|
|
|
|
225
|
88
|
|
|
|
|
2134
|
my @files; |
226
|
88
|
|
|
|
|
235
|
foreach my $filename (@$filenames) { |
227
|
368
|
100
|
|
|
|
889
|
push(@files, $filename) if $self->match_file($filename); |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
88
|
|
|
|
|
349
|
return @files; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
234
|
|
|
|
|
|
|
# Find the newest file in a set of files |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub find_newest_file { |
237
|
20
|
|
|
20
|
0
|
54
|
my ($self, @files) = @_; |
238
|
|
|
|
|
|
|
|
239
|
20
|
|
|
|
|
41
|
my ($newest_file, $newest_date); |
240
|
20
|
|
100
|
|
|
109
|
while (@files && ! defined $newest_file) { |
241
|
16
|
|
|
|
|
31
|
$newest_file = shift(@files); |
242
|
16
|
100
|
|
|
|
75
|
$newest_date =fio_get_date($newest_file) if defined $newest_file; |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
20
|
|
|
|
|
56
|
foreach my $file (@files) { |
246
|
22
|
50
|
33
|
|
|
335
|
next unless defined $file && -e $file; |
247
|
|
|
|
|
|
|
|
248
|
22
|
|
|
|
|
94
|
my $date = fio_get_date($file); |
249
|
22
|
100
|
|
|
|
81
|
if ($date > $newest_date) { |
250
|
15
|
|
|
|
|
22
|
$newest_date = $date; |
251
|
15
|
|
|
|
|
30
|
$newest_file = $file; |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
20
|
|
|
|
|
55
|
return $newest_file; |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
259
|
|
|
|
|
|
|
# Get the more recently changed files |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
sub find_top_files { |
262
|
19
|
|
|
19
|
0
|
44
|
my ($self, $folder, $augmented_files) = @_; |
263
|
|
|
|
|
|
|
|
264
|
19
|
|
|
|
|
48
|
my @files = $self->find_matching_files($folder); |
265
|
19
|
|
|
|
|
85
|
my @sorted_files = $self->sort_with_field(\@files, 'mdate', 1); |
266
|
|
|
|
|
|
|
|
267
|
19
|
|
|
|
|
80
|
return $self->merge_augmented($augmented_files, \@sorted_files); |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
271
|
|
|
|
|
|
|
# Format the file creation date |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
sub format_date { |
274
|
48
|
|
|
48
|
0
|
790
|
my ($self, $sorted_order, $date) = @_; |
275
|
|
|
|
|
|
|
|
276
|
48
|
100
|
|
|
|
113
|
if ($sorted_order) { |
277
|
1
|
|
|
|
|
3
|
$date = fio_format_date($date); |
278
|
|
|
|
|
|
|
} else { |
279
|
47
|
|
|
|
|
159
|
$date = fio_format_date($date, $self->{date_format}); |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
|
282
|
48
|
|
|
|
|
182
|
return $date; |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
286
|
|
|
|
|
|
|
# Format the file modification date |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
sub format_mdate { |
289
|
92
|
|
|
92
|
0
|
190
|
my ($self, $sorted_order, $date) = @_; |
290
|
92
|
|
|
|
|
249
|
return fio_format_date($date); |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
294
|
|
|
|
|
|
|
# Make filenames sortable in a cross-os manner |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
sub format_name { |
297
|
139
|
|
|
139
|
0
|
276
|
my ($self, $sorted_order, $filename) = @_; |
298
|
|
|
|
|
|
|
|
299
|
139
|
50
|
|
|
|
502
|
$filename = join(' ', fio_split_filename($filename)) if $sorted_order; |
300
|
139
|
|
|
|
|
672
|
return $filename; |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
304
|
|
|
|
|
|
|
# Format the file size |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
sub format_size { |
307
|
2
|
|
|
2
|
0
|
1338
|
my ($self, $sorted_order, $size) = @_; |
308
|
|
|
|
|
|
|
|
309
|
2
|
100
|
|
|
|
7
|
if ($sorted_order) { |
310
|
1
|
|
|
|
|
5
|
$size = sprintf("%012d", $size); |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
} else { |
313
|
1
|
50
|
|
|
|
4
|
if ($self->{size_format}) { |
314
|
1
|
|
|
|
|
1
|
my $byte_size = $size; |
315
|
1
|
|
|
|
|
3
|
my $fmt = lc($self->{size_format}); |
316
|
|
|
|
|
|
|
|
317
|
1
|
|
|
|
|
2
|
foreach my $format (qw(b kb mb gb)) { |
318
|
2
|
100
|
|
|
|
5
|
if ($fmt eq $format) { |
319
|
1
|
|
|
|
|
2
|
undef $fmt; |
320
|
1
|
|
|
|
|
2
|
last; |
321
|
|
|
|
|
|
|
} |
322
|
1
|
|
|
|
|
2
|
$byte_size /= 1024; |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
$size = join('', int($byte_size), $self->{size_format}) |
326
|
1
|
50
|
|
|
|
5
|
unless $fmt; |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
|
330
|
2
|
|
|
|
|
7
|
return $size; |
331
|
|
|
|
|
|
|
} |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
334
|
|
|
|
|
|
|
# Get the absolute url from a filename and the site url |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
sub get_absolute_url { |
337
|
1
|
|
|
1
|
0
|
641
|
my ($self, $filename) = @_; |
338
|
1
|
|
|
|
|
4
|
$filename = $self->dir_to_filename($filename); |
339
|
|
|
|
|
|
|
|
340
|
1
|
|
|
|
|
4
|
my $site_url = $self->get_site_url($filename); |
341
|
1
|
|
|
|
|
4
|
my $relative_url = $self->get_url($filename); |
342
|
1
|
|
|
|
|
3
|
my $absolute_url = "$site_url/$relative_url"; |
343
|
|
|
|
|
|
|
|
344
|
1
|
|
|
|
|
3
|
return $absolute_url; |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
348
|
|
|
|
|
|
|
# Get a list of matching files in a folder and its subfolders |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
sub get_all_files { |
351
|
2
|
|
|
2
|
0
|
723
|
my ($self, $filename) = @_; |
352
|
|
|
|
|
|
|
|
353
|
2
|
|
|
|
|
7
|
my ($folder) = fio_split_filename($filename); |
354
|
2
|
|
|
|
|
9
|
my @files = $self->find_matching_files($folder); |
355
|
|
|
|
|
|
|
|
356
|
2
|
|
|
|
|
10
|
my @folders = $self->find_matching_directories($folder); |
357
|
2
|
|
|
|
|
5
|
foreach my $subfolder (@folders) { |
358
|
1
|
|
|
|
|
3
|
push(@files, $self->find_matching_files($subfolder)); |
359
|
|
|
|
|
|
|
} |
360
|
|
|
|
|
|
|
|
361
|
2
|
|
|
|
|
9
|
return \@files; |
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
365
|
|
|
|
|
|
|
# Get a list of breadcrumb filenames |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
sub get_breadcrumbs { |
368
|
1
|
|
|
1
|
0
|
672
|
my ($self, $filename) = @_; |
369
|
|
|
|
|
|
|
|
370
|
1
|
|
|
|
|
4
|
my @path = splitdir(abs2rel($filename, $self->{top_directory})); |
371
|
1
|
|
|
|
|
60
|
pop(@path); |
372
|
|
|
|
|
|
|
|
373
|
1
|
|
|
|
|
2
|
my @breadcrumbs; |
374
|
1
|
|
|
|
|
2
|
for (;;) { |
375
|
|
|
|
|
|
|
my $dir = @path ? catfile($self->{top_directory}, @path) |
376
|
2
|
100
|
|
|
|
10
|
: $self->{top_directory}; |
377
|
|
|
|
|
|
|
|
378
|
2
|
|
|
|
|
5
|
my $breadcrumb = $self->dir_to_filename($dir); |
379
|
2
|
|
|
|
|
4
|
push (@breadcrumbs, $breadcrumb); |
380
|
|
|
|
|
|
|
|
381
|
2
|
100
|
|
|
|
6
|
last unless @path; |
382
|
1
|
|
|
|
|
2
|
pop(@path); |
383
|
|
|
|
|
|
|
} |
384
|
|
|
|
|
|
|
|
385
|
1
|
|
|
|
|
2
|
@breadcrumbs = reverse(@breadcrumbs); |
386
|
1
|
|
|
|
|
5
|
return \@breadcrumbs; |
387
|
|
|
|
|
|
|
} |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
390
|
|
|
|
|
|
|
# Get the extension from a filename |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
sub get_extension { |
393
|
1
|
|
|
1
|
0
|
648
|
my ($self, $filename) = @_; |
394
|
|
|
|
|
|
|
|
395
|
1
|
|
|
|
|
4
|
my ($folder, $file) = fio_split_filename($filename); |
396
|
1
|
|
|
|
|
6
|
my ($extension) = ($file =~ /\.([^\.]*)$/); |
397
|
|
|
|
|
|
|
|
398
|
1
|
|
|
|
|
4
|
return $extension; |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
403
|
|
|
|
|
|
|
# Get a list of matching files in a folder |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
sub get_files { |
406
|
47
|
|
|
47
|
0
|
510
|
my ($self, $filename) = @_; |
407
|
|
|
|
|
|
|
|
408
|
47
|
|
|
|
|
152
|
my ($folder) = fio_split_filename($filename); |
409
|
47
|
|
|
|
|
227
|
my @files = $self->find_matching_files($folder); |
410
|
47
|
|
|
|
|
184
|
return \@files; |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
414
|
|
|
|
|
|
|
# Get a list of matching directories |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
sub get_folders { |
417
|
52
|
|
|
52
|
0
|
777
|
my ($self, $filename) = @_; |
418
|
|
|
|
|
|
|
|
419
|
52
|
|
|
|
|
210
|
my ($folder) = fio_split_filename($filename); |
420
|
52
|
|
|
|
|
195
|
my ($filenames, $subfolders) = fio_visit($folder); |
421
|
|
|
|
|
|
|
|
422
|
52
|
|
|
|
|
1139
|
my @folders; |
423
|
52
|
|
|
|
|
155
|
foreach my $subfolder (@$subfolders) { |
424
|
28
|
100
|
|
|
|
119
|
next unless $self->match_directory($subfolder); |
425
|
24
|
|
|
|
|
67
|
push(@folders, $subfolder); |
426
|
|
|
|
|
|
|
} |
427
|
|
|
|
|
|
|
|
428
|
52
|
|
|
|
|
222
|
return \@folders; |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
432
|
|
|
|
|
|
|
# Get the url of the index page in the same folder as a file |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
sub get_index_url { |
435
|
7
|
|
|
7
|
0
|
678
|
my ($self, $filename) = @_; |
436
|
|
|
|
|
|
|
|
437
|
7
|
|
|
|
|
24
|
my ($dir, $file) = fio_split_filename($filename); |
438
|
7
|
|
|
|
|
24
|
my $index_page = "index.$self->{web_extension}"; |
439
|
7
|
|
|
|
|
28
|
$index_page = catfile($dir, $index_page); |
440
|
|
|
|
|
|
|
|
441
|
7
|
|
|
|
|
32
|
return $self->get_url($index_page); |
442
|
|
|
|
|
|
|
} |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
445
|
|
|
|
|
|
|
# Set a flag indicating if the the filename is the index file |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
sub get_is_index { |
448
|
2
|
|
|
2
|
0
|
1361
|
my ($self, $filename) = @_; |
449
|
|
|
|
|
|
|
|
450
|
2
|
|
|
|
|
6
|
my ($folder, $file) = fio_split_filename($filename); |
451
|
2
|
|
|
|
|
7
|
my ($root, $ext) = split(/\./, $file); |
452
|
|
|
|
|
|
|
|
453
|
2
|
|
66
|
|
|
11
|
my $is_index = $root eq 'index' && $ext eq $self->{web_extension}; |
454
|
2
|
100
|
|
|
|
8
|
return $is_index ? 1 : 0; |
455
|
|
|
|
|
|
|
} |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
458
|
|
|
|
|
|
|
# Get the modification time in epoch seconds |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
sub get_mdate { |
461
|
97
|
|
|
97
|
0
|
199
|
my ($self, $filename) = @_; |
462
|
|
|
|
|
|
|
|
463
|
97
|
|
|
|
|
274
|
return fio_get_date($filename); |
464
|
|
|
|
|
|
|
} |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
467
|
|
|
|
|
|
|
# Get the most recently modified file in a folder and its subfolders |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
sub get_newest_file { |
470
|
14
|
|
|
14
|
0
|
658
|
my ($self, $filename) = @_; |
471
|
|
|
|
|
|
|
|
472
|
14
|
|
|
|
|
55
|
my ($folder) = fio_split_filename($filename); |
473
|
14
|
|
|
|
|
86
|
my @files = $self->find_matching_files($folder); |
474
|
|
|
|
|
|
|
|
475
|
14
|
|
|
|
|
89
|
my $newest_file = $self->find_newest_file(@files); |
476
|
14
|
|
|
|
|
64
|
my @folders = $self->find_matching_directories($folder); |
477
|
|
|
|
|
|
|
|
478
|
14
|
|
|
|
|
31
|
foreach my $subfolder (@folders) { |
479
|
6
|
|
|
|
|
22
|
@files = $self->find_matching_files($subfolder); |
480
|
6
|
|
|
|
|
20
|
$newest_file = $self->find_newest_file($newest_file, @files); |
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
|
483
|
14
|
100
|
|
|
|
85
|
return defined $newest_file ? [$newest_file] : []; |
484
|
|
|
|
|
|
|
} |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
487
|
|
|
|
|
|
|
# Get a list of files with the same rootname as another filename |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
sub get_related_files { |
490
|
1
|
|
|
1
|
0
|
567
|
my ($self, $filename) = @_; |
491
|
1
|
|
|
|
|
4
|
my ($folder, $file) = fio_split_filename($filename); |
492
|
|
|
|
|
|
|
|
493
|
1
|
|
|
|
|
2
|
my $root; |
494
|
1
|
|
|
|
|
6
|
($root = $file) =~ s/\.[^\.]*$//; |
495
|
|
|
|
|
|
|
|
496
|
1
|
|
|
|
|
2
|
my @related_files; |
497
|
1
|
|
|
|
|
3
|
my ($filenames, $folders) = fio_visit($folder); |
498
|
1
|
|
|
|
|
21
|
foreach my $filename (@$filenames) { |
499
|
10
|
|
|
|
|
22
|
my ($folder, $file) = fio_split_filename($filename); |
500
|
|
|
|
|
|
|
|
501
|
10
|
|
|
|
|
16
|
my $rootname; |
502
|
10
|
|
|
|
|
42
|
($rootname = $file) =~ s/\.[^\.]*$//; |
503
|
10
|
100
|
|
|
|
31
|
push(@related_files, $filename) if $root eq $rootname; |
504
|
|
|
|
|
|
|
} |
505
|
|
|
|
|
|
|
|
506
|
1
|
|
|
|
|
5
|
return \@related_files; |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
510
|
|
|
|
|
|
|
# Get the remote url from a filename and the remote url |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
sub get_remote_url { |
513
|
29
|
|
|
29
|
0
|
731
|
my ($self, $filename) = @_; |
514
|
|
|
|
|
|
|
|
515
|
29
|
|
|
|
|
75
|
my $remote_url; |
516
|
29
|
50
|
|
|
|
63
|
if ($self->{remote_url}) { |
517
|
29
|
|
|
|
|
73
|
my $relative_url = $self->get_url($filename); |
518
|
29
|
|
|
|
|
87
|
$remote_url = "$self->{remote_url}/$relative_url"; |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
} else { |
521
|
0
|
|
|
|
|
0
|
$remote_url = $self->get_absolute_url($filename); |
522
|
|
|
|
|
|
|
} |
523
|
|
|
|
|
|
|
|
524
|
29
|
|
|
|
|
85
|
return $remote_url; |
525
|
|
|
|
|
|
|
} |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
528
|
|
|
|
|
|
|
# get the site url |
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
sub get_site_url { |
531
|
36
|
|
|
36
|
0
|
731
|
my ($self, $filename) = @_; |
532
|
|
|
|
|
|
|
|
533
|
36
|
|
|
|
|
56
|
my $site_url ; |
534
|
36
|
100
|
|
|
|
92
|
if ($self->{site_url}) { |
535
|
18
|
|
|
|
|
25
|
$site_url = $self->{site_url}; |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
} else { |
538
|
18
|
|
|
|
|
54
|
$site_url = 'file://' . $self->{top_directory}; |
539
|
|
|
|
|
|
|
} |
540
|
|
|
|
|
|
|
|
541
|
36
|
|
|
|
|
77
|
$site_url =~ s/\/$//; |
542
|
36
|
|
|
|
|
93
|
return $site_url; |
543
|
|
|
|
|
|
|
} |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
546
|
|
|
|
|
|
|
# Get the file size |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
sub get_size { |
549
|
1
|
|
|
1
|
0
|
8
|
my ($self, $filename) = @_; |
550
|
|
|
|
|
|
|
|
551
|
1
|
|
|
|
|
4
|
return fio_get_size($filename); |
552
|
|
|
|
|
|
|
} |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
555
|
|
|
|
|
|
|
# Get a list of matching files in a directory and its subdirectories |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
sub get_top_files { |
558
|
10
|
|
|
10
|
0
|
642
|
my ($self, $filename) = @_; |
559
|
|
|
|
|
|
|
|
560
|
10
|
|
|
|
|
26
|
my $augmented_files = []; |
561
|
10
|
|
|
|
|
36
|
my ($folder) = fio_split_filename($filename); |
562
|
10
|
|
|
|
|
47
|
$augmented_files = $self->find_top_files($folder, $augmented_files); |
563
|
|
|
|
|
|
|
|
564
|
10
|
|
|
|
|
38
|
my @directories = $self->find_matching_directories($folder); |
565
|
|
|
|
|
|
|
|
566
|
10
|
|
|
|
|
26
|
foreach my $subfolder (@directories) { |
567
|
9
|
|
|
|
|
24
|
$augmented_files = $self->find_top_files($subfolder, |
568
|
|
|
|
|
|
|
$augmented_files); |
569
|
|
|
|
|
|
|
} |
570
|
|
|
|
|
|
|
|
571
|
10
|
|
|
|
|
45
|
my @top_files = $self->strip_augmented(@$augmented_files); |
572
|
10
|
|
|
|
|
37
|
return \@top_files; |
573
|
|
|
|
|
|
|
} |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
576
|
|
|
|
|
|
|
# Get a url from a filename |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
sub get_url { |
579
|
67
|
|
|
67
|
0
|
2073
|
my ($self, $filename) = @_; |
580
|
67
|
|
|
|
|
174
|
$filename = $self->dir_to_filename($filename); |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
return $self->filename_to_url($self->{top_directory}, |
583
|
|
|
|
|
|
|
$filename, |
584
|
67
|
|
|
|
|
260
|
$self->{web_extension}); |
585
|
|
|
|
|
|
|
} |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
588
|
|
|
|
|
|
|
# Get a url with no extension from a filename |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
sub get_url_base { |
591
|
1
|
|
|
1
|
0
|
670
|
my ($self, $filename) = @_; |
592
|
1
|
|
|
|
|
3
|
$filename = $self->dir_to_filename($filename); |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
my $url_base = $self->filename_to_url($self->{top_directory}, |
595
|
1
|
|
|
|
|
4
|
$filename, ''); |
596
|
1
|
|
|
|
|
4
|
chop($url_base); # remove trailing dot |
597
|
1
|
|
|
|
|
4
|
return $url_base; |
598
|
|
|
|
|
|
|
} |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
601
|
|
|
|
|
|
|
# Get a url from the next filename in the loop |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
sub get_url_next { |
604
|
5
|
|
|
5
|
0
|
23
|
my ($self, $filename, $loop) = @_; |
605
|
|
|
|
|
|
|
|
606
|
5
|
|
|
|
|
11
|
$filename = $self->find_filename(1, $filename, $loop); |
607
|
5
|
100
|
|
|
|
16
|
return $filename ? $self->get_url($filename) : ''; |
608
|
|
|
|
|
|
|
} |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
611
|
|
|
|
|
|
|
# Get a url from the previous filename in the loop |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
sub get_url_previous { |
614
|
5
|
|
|
5
|
0
|
21
|
my ($self, $filename, $loop) = @_; |
615
|
|
|
|
|
|
|
|
616
|
5
|
|
|
|
|
11
|
$filename = $self->find_filename(-1, $filename, $loop); |
617
|
5
|
100
|
|
|
|
15
|
return $filename ? $self->get_url($filename) : ''; |
618
|
|
|
|
|
|
|
} |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
621
|
|
|
|
|
|
|
# Return true if this is an included directory |
622
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
sub match_directory { |
624
|
44
|
|
|
44
|
0
|
100
|
my ($self, $directory) = @_; |
625
|
|
|
|
|
|
|
|
626
|
44
|
|
66
|
|
|
173
|
$self->{exclude_dir_patterns} ||= fio_glob_patterns($self->{exclude_dirs}); |
627
|
|
|
|
|
|
|
|
628
|
44
|
100
|
|
|
|
117
|
return if $self->match_patterns($directory, $self->{exclude_dir_patterns}); |
629
|
40
|
|
|
|
|
112
|
return 1; |
630
|
|
|
|
|
|
|
} |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
633
|
|
|
|
|
|
|
# Return true if this is an included file |
634
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
sub match_file { |
636
|
413
|
|
|
413
|
0
|
750
|
my ($self, $filename) = @_; |
637
|
|
|
|
|
|
|
|
638
|
413
|
|
|
|
|
895
|
my ($dir, $file) = fio_split_filename($filename); |
639
|
|
|
|
|
|
|
|
640
|
413
|
100
|
|
|
|
1210
|
if ($self->{exclude_index}) { |
641
|
130
|
|
|
|
|
316
|
my $index_file = join('.', 'index', $self->{web_extension}); |
642
|
130
|
100
|
|
|
|
413
|
return if $file eq $index_file; |
643
|
|
|
|
|
|
|
} |
644
|
|
|
|
|
|
|
|
645
|
372
|
|
|
|
|
1253
|
my @patterns = map {"*.$_"} split(/\s*,\s*/, $self->{extension}); |
|
426
|
|
|
|
|
1230
|
|
646
|
372
|
|
|
|
|
784
|
my $patterns = join(',', @patterns); |
647
|
|
|
|
|
|
|
|
648
|
372
|
|
66
|
|
|
1085
|
$self->{include_file_patterns} ||= fio_glob_patterns($patterns); |
649
|
372
|
|
66
|
|
|
901
|
$self->{exclude_file_patterns} ||= fio_glob_patterns($self->{exclude}); |
650
|
|
|
|
|
|
|
|
651
|
372
|
100
|
|
|
|
964
|
return if $self->match_patterns($file, $self->{exclude_file_patterns}); |
652
|
363
|
100
|
|
|
|
718
|
return unless $self->match_patterns($file, $self->{include_file_patterns}); |
653
|
219
|
|
|
|
|
875
|
return 1; |
654
|
|
|
|
|
|
|
} |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
657
|
|
|
|
|
|
|
# Return true if filename matches pattern |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
sub match_patterns { |
660
|
788
|
|
|
788
|
0
|
1370
|
my ($self, $file, $patterns) = @_; |
661
|
|
|
|
|
|
|
|
662
|
788
|
|
|
|
|
1560
|
my @path = splitdir($file); |
663
|
788
|
|
|
|
|
3324
|
$file = pop(@path); |
664
|
|
|
|
|
|
|
|
665
|
788
|
|
|
|
|
1440
|
foreach my $pattern (@$patterns) { |
666
|
491
|
100
|
|
|
|
4186
|
return 1 if $file =~ /$pattern/; |
667
|
|
|
|
|
|
|
} |
668
|
|
|
|
|
|
|
|
669
|
556
|
|
|
|
|
1539
|
return; |
670
|
|
|
|
|
|
|
} |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
673
|
|
|
|
|
|
|
# Initialize the configuration parameters |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
sub setup { |
676
|
91
|
|
|
91
|
1
|
219
|
my ($self) = @_; |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
# Set filename extension if unset |
679
|
91
|
|
66
|
|
|
570
|
$self->{extension} ||= $self->{web_extension}; |
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
# Remove any trailing slash from urls |
682
|
91
|
|
|
|
|
184
|
foreach my $url (qw(remote_url site_url)) { |
683
|
182
|
100
|
|
|
|
447
|
next unless $self->{$url}; |
684
|
23
|
|
|
|
|
55
|
$self->{$url} =~ s/\/$//; |
685
|
|
|
|
|
|
|
} |
686
|
|
|
|
|
|
|
|
687
|
91
|
|
|
|
|
205
|
return; |
688
|
|
|
|
|
|
|
} |
689
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
1; |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
=pod |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
=encoding utf-8 |
695
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
=head1 NAME |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
App::Followme::FolderData - Build metadata from folder information |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
=head1 SYNOPSIS |
701
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
use Cwd; |
703
|
|
|
|
|
|
|
use App::Followme::FolderData; |
704
|
|
|
|
|
|
|
my $directory = getcwd(); |
705
|
|
|
|
|
|
|
my $data = App::Followme::FolderData->new(); |
706
|
|
|
|
|
|
|
my $filenames = $data->get_files($directory); |
707
|
|
|
|
|
|
|
foreach my $filename (@$filenames) { |
708
|
|
|
|
|
|
|
print "$filename\n"; |
709
|
|
|
|
|
|
|
} |
710
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
=head1 DESCRIPTION |
712
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
This module contains the methods that build metadata values that can be computed |
714
|
|
|
|
|
|
|
from properties of the file system, that is, without opening a file or |
715
|
|
|
|
|
|
|
without regard to the type of file. It serves as the base of all the metadata |
716
|
|
|
|
|
|
|
classes that build metadata for specific file types. |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
=head1 METHODS |
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
All data are accessed through the build method. |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
=over 4 |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
=item my %data = $obj->build($name, $filename); |
725
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
Build a variable's value. The first argument is the name of the variable. The |
727
|
|
|
|
|
|
|
second argument is the name of the file the metadata is being computed for. If |
728
|
|
|
|
|
|
|
it is undefined, the filename in the object |
729
|
|
|
|
|
|
|
is used. |
730
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
=back |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
=head1 VARIABLES |
734
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
The folder metadata class can evaluate the following variables. When passing |
736
|
|
|
|
|
|
|
a name to the build method, the sigil should not be used. |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
=over 4 |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
=item @all_files |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
A list of matching files in a directory and its subdirectories. |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
=item @top_files |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
A list of the most recently created files in a directory and its |
747
|
|
|
|
|
|
|
subdirectory. The length of the list is determined by the |
748
|
|
|
|
|
|
|
configuration parameter list_length. |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
=item @breadcrumbs |
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
A list of breadcrumb filenames, which are the names of the index files |
753
|
|
|
|
|
|
|
above the filename passed as the argument. |
754
|
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
=item @related_files |
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
A list of files with the same file root name as a specified file. This |
758
|
|
|
|
|
|
|
list is not filtered by the configuration variables extension and exclude. |
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
=item @files |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
A list of matching files in a directory. |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
=item @folders |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
A list of folders under the default folder that contain an index file. |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
=item $author |
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
The name of the author of a file |
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
=item $absolute_url |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
The absolute url of a web page from a filename. |
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
=item $date |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
A date string built from the creation date of the file. The date is |
779
|
|
|
|
|
|
|
built using the template in date_format which contains the fields: |
780
|
|
|
|
|
|
|
C<weekday, month,day, year, hour, minute,> and C<second.> |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
=item $mdate |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
A date string built from the modification date of the file. The date is |
785
|
|
|
|
|
|
|
built using the template in date_format which contains the fields: |
786
|
|
|
|
|
|
|
C<weekday, month,day, year, hour, minute,> and C<second.> |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
=item $is_current |
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
One if the filename matches the default filename, zero if it does not. |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
=item $is_index |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
One of the filename is an index file and zero if it is not. |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
=item $keywords |
797
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
A list of keywords describing the file from the filename path. |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
=item $remote_url |
801
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
The remote url of a web page from a filename. |
803
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
=item $site_url |
805
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
The url of the website. Does not have a trailing slash |
807
|
|
|
|
|
|
|
|
808
|
|
|
|
|
|
|
=item $index_url |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
The url of the index page in the same folder as a file. |
811
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
=item $title |
813
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
The title of a file is derived from the file name by removing the filename |
815
|
|
|
|
|
|
|
extension, removing any leading digits,replacing dashes with spaces, and |
816
|
|
|
|
|
|
|
capitalizing the first character of each word. |
817
|
|
|
|
|
|
|
|
818
|
|
|
|
|
|
|
=item $url |
819
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
Build the relative url of a web page from a filename. |
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
=item $url_base |
823
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
Build the relative url of a filename minus any extension and trailing dot |
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
=item $extension |
827
|
|
|
|
|
|
|
|
828
|
|
|
|
|
|
|
The extension of a filename. |
829
|
|
|
|
|
|
|
|
830
|
|
|
|
|
|
|
=item $url_next |
831
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
Build the relative url of a web page from the next filename in the loop |
833
|
|
|
|
|
|
|
sequence. Empty string if there is no next filename. |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
=item $url_previous |
836
|
|
|
|
|
|
|
|
837
|
|
|
|
|
|
|
Build the relative url of a web page from the previous filename in the loop |
838
|
|
|
|
|
|
|
sequence. Empty string if there is no previous filename. |
839
|
|
|
|
|
|
|
|
840
|
|
|
|
|
|
|
=back |
841
|
|
|
|
|
|
|
|
842
|
|
|
|
|
|
|
=head1 CONFIGURATION |
843
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
The following fields in the configuration file are used in this class and every |
845
|
|
|
|
|
|
|
class based on it: |
846
|
|
|
|
|
|
|
|
847
|
|
|
|
|
|
|
=over 4 |
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
=item filename |
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
The filename used to retrieve metatdata from if no filename is passed to the |
852
|
|
|
|
|
|
|
build method. |
853
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
=item directory |
855
|
|
|
|
|
|
|
|
856
|
|
|
|
|
|
|
The directory used to retrieve metadata. This is used by list valued variables. |
857
|
|
|
|
|
|
|
|
858
|
|
|
|
|
|
|
=item extension |
859
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
A comma separated list of extensions of files to include in a list of files. |
861
|
|
|
|
|
|
|
If it is left empty, it is set to the web extension. |
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
=item date_format |
864
|
|
|
|
|
|
|
|
865
|
|
|
|
|
|
|
The format used to produce date strings. The format is described in the |
866
|
|
|
|
|
|
|
POD for Time::Format. |
867
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
=item remote_url |
869
|
|
|
|
|
|
|
|
870
|
|
|
|
|
|
|
The url of the remote website, e.g. http://www.cloudhost.com. |
871
|
|
|
|
|
|
|
|
872
|
|
|
|
|
|
|
=item site_url |
873
|
|
|
|
|
|
|
|
874
|
|
|
|
|
|
|
The url of the local website, e.g. http://www.example.com. |
875
|
|
|
|
|
|
|
|
876
|
|
|
|
|
|
|
=item sort_numeric |
877
|
|
|
|
|
|
|
|
878
|
|
|
|
|
|
|
If one, use numeric comparisons when sorting. If zero, use string comparisons |
879
|
|
|
|
|
|
|
when sorting. |
880
|
|
|
|
|
|
|
|
881
|
|
|
|
|
|
|
=item exclude_index |
882
|
|
|
|
|
|
|
|
883
|
|
|
|
|
|
|
If the value of this variable is true (1) exclude the index page in the list |
884
|
|
|
|
|
|
|
of files. If it is false (0) include the index page. The default value is 0. |
885
|
|
|
|
|
|
|
|
886
|
|
|
|
|
|
|
=item exclude |
887
|
|
|
|
|
|
|
|
888
|
|
|
|
|
|
|
The files to exclude when traversing the list of files. Leave as a zero length |
889
|
|
|
|
|
|
|
string if there are no files to exclude. |
890
|
|
|
|
|
|
|
|
891
|
|
|
|
|
|
|
=item exclude_dirs |
892
|
|
|
|
|
|
|
|
893
|
|
|
|
|
|
|
The directories excluded while traversing the list of directories. The default |
894
|
|
|
|
|
|
|
value of this parameter is '.*,_*', |
895
|
|
|
|
|
|
|
|
896
|
|
|
|
|
|
|
=item web_extension |
897
|
|
|
|
|
|
|
|
898
|
|
|
|
|
|
|
The extension used by web pages. This controls which files are returned. The |
899
|
|
|
|
|
|
|
default value is 'html'. |
900
|
|
|
|
|
|
|
|
901
|
|
|
|
|
|
|
=back |
902
|
|
|
|
|
|
|
|
903
|
|
|
|
|
|
|
=head1 LICENSE |
904
|
|
|
|
|
|
|
|
905
|
|
|
|
|
|
|
Copyright (C) Bernie Simon. |
906
|
|
|
|
|
|
|
|
907
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
908
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
909
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
=head1 AUTHOR |
911
|
|
|
|
|
|
|
|
912
|
|
|
|
|
|
|
Bernie Simon E<lt>bernie.simon@gmail.comE<gt> |
913
|
|
|
|
|
|
|
|
914
|
|
|
|
|
|
|
=cut |