File Coverage

blib/lib/Archive/Dir.pm
Criterion Covered Total %
statement 15 33 45.4
branch 0 8 0.0
condition 0 2 0.0
subroutine 6 10 60.0
pod 0 6 0.0
total 21 59 35.5


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