File Coverage

blib/lib/Archive/Merged.pm
Criterion Covered Total %
statement 19 34 55.8
branch 1 6 16.6
condition n/a
subroutine 6 10 60.0
pod 7 7 100.0
total 33 57 57.8


line stmt bran cond sub pod time code
1             package Archive::Merged;
2 2     2   25842 use strict;
  2         3  
  2         48  
3 2     2   6 use Carp qw(croak);
  2         2  
  2         87  
4 2     2   7 use vars qw($VERSION);
  2         5  
  2         551  
5             $VERSION = '0.01';
6              
7             =head1 NAME
8              
9             Archive::Merged - virtually merge two archives
10              
11             =head1 SYNOPSIS
12              
13             my $merged = Archive::Merged->new(
14             Archive::Tar->new( 'default_theme.tar' ),
15             Archive::SevenZip->archiveTarApi( archivename => 'theme.zip' ),
16             Archive::Dir->new( 'customized/' ),
17             );
18              
19             =head1 METHODS
20              
21             =head2 C<< Archive::Merged->new >>
22              
23             my $merged = Archive::Merged->new(
24             Archive::Tar->new( 'default_theme.tar' ),
25             Archive::Dir->new( 'customized/' ),
26             );
27              
28             Creates a new archive as the merged view of one or more archives
29             or directories.
30              
31             =cut
32              
33             sub new {
34 1     1 1 3 my ($class, @archives) = @_;
35 1         1 my $self = {
36             archives => \@archives,
37             };
38 1         2 bless $self => $class;
39 1         2 $self
40             };
41              
42             =head2 C<< ->directory >>
43              
44             =cut
45              
46             sub directory {
47             undef
48 0     0 1 0 };
49              
50             =head2 C<< ->archives >>
51              
52             my @archives = $merged->archives;
53              
54             Accessor for the archives that represent this archive.
55              
56             =cut
57              
58             sub archives {
59 1     1 1 1 @{ $_[0]->{archives} }
  1         4  
60             }
61              
62             =head2 C<< ->contains_file >>
63              
64             if( $merged->contains_file( $file ) ) {
65             print "Yay!"
66             } else {
67             print "File '$file' not found";
68             };
69              
70             Returns the underlying archive that contains the file. Returns
71             undef if the file is not found.
72              
73             =cut
74              
75             sub contains_file {
76 1     1 1 3 my( $self, $file ) = @_;
77 1         3 for my $ar ($self->archives) {
78 1 50       4 if( $ar->contains_file( $file ) ) {
79 1         166 return $ar
80             };
81             };
82             };
83              
84             =head2 C<< ->get_content( $file, %options ) >>
85              
86             my $content = $merged->get_content( $file, binmode => ':raw' )
87              
88             Returns the content of the file, potentially with the encoding.
89              
90             =cut
91              
92             sub get_content {
93 0     0 1   my( $self, $file, %options ) = @_;
94 0           my $ar = $self->contains_file( $file );
95 0           $ar->get_content( $file, %options )
96             };
97              
98             =head2 C<< ->list_files( ) >>
99              
100             my @contents = $merged->list_files;
101              
102             Lists the contained files of the archive. Files that are shadowed
103             are only listed once.
104              
105             =cut
106              
107             sub list_files {
108 0     0 1   my ($self,$properties) = @_;
109 0 0         croak "Listing properties is not (yet) implemented"
110             if $properties;
111 0           my %seen;
112             my @files;
113 0           for my $ar ($self->archives) {
114 0           for my $file ($ar->list_files) {
115 0 0         if( ! $seen{ $file }++) {
116 0           push @files, $file;
117             };
118             };
119             };
120             @files
121 0           }
122              
123             =head2 C<< ->extract_file( ) >>
124              
125             $merged->extract_file( $name => $target );
126              
127             Extracts the file to the target name.
128              
129             =cut
130              
131             sub extract_file {
132 0     0 1   my ($self,$file,$target) = @_;
133 0           my $ar = $self->contains_file( $file );
134 0           $ar->extract_file( $file, $target );
135             };
136              
137             1;
138              
139             =head1 REPOSITORY
140              
141             The public repository of this module is
142             L.
143              
144             =head1 SUPPORT
145              
146             The public support forum of this module is
147             L.
148              
149             =head1 BUG TRACKER
150              
151             Please report bugs in this module via the RT CPAN bug queue at
152             L
153             or via mail to L.
154              
155             =head1 AUTHOR
156              
157             Max Maischein C
158              
159             =head1 COPYRIGHT (c)
160              
161             Copyright 2015-2016 by Max Maischein C.
162              
163             =head1 LICENSE
164              
165             This module is released under the same terms as Perl itself.
166              
167             =cut
168              
169             =head1 SEE ALSO
170              
171             L
172              
173             L
174              
175             =cut