Merged.pm

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