line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML5::Manifest; |
2
|
2
|
|
|
2
|
|
953
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
71
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
78
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Digest::MD5; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
94
|
|
7
|
2
|
|
|
2
|
|
10
|
use File::Spec; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
47
|
|
8
|
2
|
|
|
2
|
|
1844
|
use IO::Dir; |
|
2
|
|
|
|
|
61068
|
|
|
2
|
|
|
|
|
1398
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
1
|
|
|
1
|
1
|
60
|
my($class, %args) = @_; |
12
|
1
|
|
|
|
|
10
|
bless { |
13
|
|
|
|
|
|
|
%args |
14
|
|
|
|
|
|
|
}, $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _recurse { |
18
|
3
|
|
|
3
|
|
7
|
my($self, $path, $cb) = @_; |
19
|
|
|
|
|
|
|
|
20
|
3
|
50
|
|
|
|
25
|
my $dir = IO::Dir->new($path) or die "Can't open directory $path: $!"; |
21
|
3
|
|
|
|
|
271
|
my @list; |
22
|
3
|
|
|
|
|
12
|
while (defined(my $entry = $dir->read)) { |
23
|
15
|
100
|
100
|
|
|
531
|
next if $entry eq File::Spec->updir || $entry eq File::Spec->curdir; |
24
|
9
|
|
|
|
|
39
|
push @list, $entry; |
25
|
|
|
|
|
|
|
} |
26
|
3
|
|
|
|
|
39
|
for my $entry (sort @list) { |
27
|
9
|
|
|
|
|
151
|
my $new_path = File::Spec->catfile($path, $entry); |
28
|
9
|
|
|
|
|
166
|
my $is_dir = -d $new_path; |
29
|
9
|
100
|
|
|
|
26
|
$entry = "$entry/" if $is_dir; |
30
|
9
|
|
|
|
|
29
|
my $is_pass = $cb->($new_path, $entry, $is_dir); |
31
|
9
|
100
|
|
|
|
34
|
next unless $is_pass; |
32
|
5
|
100
|
|
|
|
20
|
if ($is_dir) { |
33
|
2
|
|
|
|
|
12
|
$self->_recurse($new_path, $cb); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub generate { |
39
|
1
|
|
|
1
|
1
|
8
|
my $self = shift; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
27
|
my $manifest = "CACHE MANIFEST\n\n"; |
42
|
1
|
50
|
33
|
|
|
19
|
if ($self->{network} && ref $self->{network} eq 'ARRAY') { |
43
|
1
|
|
|
|
|
3
|
$manifest .= "NETWORK:\n"; |
44
|
1
|
|
|
|
|
2
|
for my $path (@{ $self->{network} }) { |
|
1
|
|
|
|
|
4
|
|
45
|
2
|
|
|
|
|
5
|
$manifest .= "$path\n"; |
46
|
|
|
|
|
|
|
} |
47
|
1
|
|
|
|
|
3
|
$manifest .= "\n"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
2
|
my $md5; |
51
|
1
|
50
|
|
|
|
12
|
$md5 = Digest::MD5->new if $self->{use_digest}; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
2
|
my $htdocs = $self->{htdocs}; |
54
|
1
|
50
|
|
|
|
6
|
$htdocs =~ s!\\!/!g if $^O eq 'MSWin32'; |
55
|
1
|
|
|
|
|
2
|
$manifest .= "CACHE:\n"; |
56
|
|
|
|
|
|
|
$self->_recurse($htdocs, sub { |
57
|
9
|
|
|
9
|
|
19
|
my($fullpath, $filename, $is_dir) = @_; |
58
|
9
|
|
|
|
|
11
|
my $manifest_path = $fullpath; |
59
|
9
|
50
|
|
|
|
45
|
$manifest_path =~ s!\\!/!g if $^O eq 'MSWin32'; |
60
|
9
|
|
|
|
|
81
|
$manifest_path =~ s/^$htdocs//; |
61
|
|
|
|
|
|
|
|
62
|
9
|
50
|
|
|
|
15
|
for my $qr (@{ $self->{skip} || [] }) { |
|
9
|
|
|
|
|
37
|
|
63
|
46
|
100
|
|
|
|
192
|
return 0 if $filename =~ $qr; |
64
|
|
|
|
|
|
|
} |
65
|
5
|
100
|
|
|
|
18
|
return 1 if $is_dir; |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
6
|
$manifest .= $manifest_path; |
68
|
3
|
50
|
|
|
|
8
|
if ($self->{use_digest}) { |
69
|
3
|
50
|
|
|
|
252
|
open my $fh, '<', $fullpath or die "Can't open file $fullpath: $!"; |
70
|
3
|
|
|
|
|
105
|
$md5->addfile($fh); |
71
|
|
|
|
|
|
|
} |
72
|
3
|
|
|
|
|
7
|
$manifest .= "\n"; |
73
|
3
|
|
|
|
|
7
|
return 1; |
74
|
1
|
|
|
|
|
11
|
}); |
75
|
1
|
50
|
|
|
|
48
|
$manifest .= "\n# digest: " . $md5->b64digest . "\n" if $self->{use_digest}; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
12
|
return $manifest; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
__END__ |