line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Archive::Dir; |
2
|
1
|
|
|
1
|
|
303
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
3
|
1
|
|
|
1
|
|
2
|
use Carp qw(croak); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
362
|
use Path::Class; |
|
1
|
|
|
|
|
29937
|
|
|
1
|
|
|
|
|
50
|
|
5
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
302
|
|
6
|
|
|
|
|
|
|
$VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Archive::Dir - a directory with an API like an Archive::Tar |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $ar = Archive::Dir->new('foo'); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 METHODS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
1
|
|
|
1
|
0
|
9
|
my ($class, $directory) = @_; |
22
|
1
|
|
|
|
|
5
|
my $self = { |
23
|
|
|
|
|
|
|
directory => dir($directory), |
24
|
|
|
|
|
|
|
}; |
25
|
1
|
|
|
|
|
112
|
bless $self => $class; |
26
|
1
|
|
|
|
|
7
|
$self |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub directory { |
30
|
|
|
|
|
|
|
$_[0]->{directory} |
31
|
1
|
|
|
1
|
0
|
5
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub contains_file { |
34
|
1
|
|
|
1
|
0
|
3
|
-f $_[0]->directory->file($_[1]) |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub get_content { |
38
|
0
|
|
|
0
|
0
|
|
my( $self, $file, %options ) = @_; |
39
|
0
|
|
0
|
|
|
|
$options{ binmode } ||= ':raw'; |
40
|
0
|
|
|
|
|
|
$options{ binmode } = "<$options{binmode}"; |
41
|
0
|
|
|
|
|
|
$self->directory->file($file)->slurp(iomode => $options{ binmode }); |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub list_files { |
45
|
0
|
|
|
0
|
0
|
|
my ($self,$properties) = @_; |
46
|
0
|
0
|
|
|
|
|
croak "Listing properties is not (yet) implemented" |
47
|
|
|
|
|
|
|
if $properties; |
48
|
0
|
|
|
|
|
|
my @files; |
49
|
0
|
0
|
|
0
|
|
|
$self->directory->recurse(callback => sub { push @files, $_[0] if !$_[0]->is_dir}); |
|
0
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
map { $_->relative( $self->directory ) } @files |
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub extract_file { |
54
|
0
|
|
|
0
|
0
|
|
my ($self,$file,$target) = @_; |
55
|
0
|
0
|
|
|
|
|
if ($self->contains_file( $file )) { |
56
|
0
|
0
|
|
|
|
|
open my $fh, '>', $target |
57
|
|
|
|
|
|
|
or croak "Couldn't create '$target': $!"; |
58
|
0
|
|
|
|
|
|
binmode $fh; |
59
|
0
|
|
|
|
|
|
print {$fh} $self->get_content($file); |
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
|
|
|
|
|
croak "'$file' is not contained in '" . $self->directory . "'"; |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 CAUTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This module does not implement any encoding/decoding for file names in |
70
|
|
|
|
|
|
|
the file system. It completely relies on L to handle this issue. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 REPOSITORY |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
The public repository of this module is |
75
|
|
|
|
|
|
|
L. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SUPPORT |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
The public support forum of this module is |
80
|
|
|
|
|
|
|
L. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 BUG TRACKER |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Please report bugs in this module via the RT CPAN bug queue at |
85
|
|
|
|
|
|
|
L |
86
|
|
|
|
|
|
|
or via mail to L. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 AUTHOR |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Max Maischein C |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 COPYRIGHT (c) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Copyright 2015-2016 by Max Maischein C. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 LICENSE |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This module is released under the same terms as Perl itself. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SEE ALSO |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
L |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
L |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |