Dir.pm

filter: Statementstmt 48.5% 17 / 35 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 6 totaltotal 37.1% 23 / 62 CC 6 SCAR 16.5
CC
6
Cov
38%
extract_file
12.0
get_content
6.0
list_files
6.0
CRAP 5.2
« Merged.pm ↑ Summary
1 package Archive::Dir;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = '0.03';
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 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
20 1 my ($class, $directory) = @_;
21 1 my $self = {
22 directory => dir($directory),
23 };
24 1 bless $self => $class;
25 1 $self
26 };
27  
28 1 ▶sub directory {
Subroutine directory: called CC=1 SCAR=0.0
Pod undocumented
29 $_[0]->{directory}
30 1 };
31  
32 1 ▶sub contains_file {
Subroutine contains_file: called CC=1 SCAR=0.0
Pod undocumented
33 1 -f $_[0]->directory->file($_[1])
34 };
35  
36 0 ▶sub get_content {
Subroutine get_content: not called CC=2 SCAR=17.9
Pod undocumented
37 0 my( $self, $file, %options ) = @_;
38 0 ▶ $options{ binmode } ||= ':raw';
Condition0%0/2
$options{"binmode"} ||= ":raw"
l!l
00
MC/DC0%0/1
$options{"binmode"} ||= ":raw"
$options{"binmode"}
Truth table0%0/2
A
A= $options{"binmode"}
Aresult
11
00
39 0 $options{ binmode } = "<$options{binmode}";
40 0 $self->directory->file($file)->slurp(iomode => $options{ binmode });
41 };
42  
43 0 ▶sub list_files {
Subroutine list_files: not called CC=2 SCAR=17.9
Pod undocumented
44 0 my ($self,$properties) = @_;
45 0 ▶ croak "Listing properties is not (yet) implemented"
Branch: 1 branch
BranchTrueFalseTotal
if $properties 0 0 0
46 if $properties;
47 0 my @files;
48 0 ▶ $self->directory->recurse(callback => sub { push @files, $_[0] if !$_[0]->is_dir});
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if not $_[0]->is_dir 0 0 0
49 0 map { $_->relative( $self->directory ) } @files
50 }
51  
52 0 ▶sub extract_file {
Subroutine extract_file: not called CC=3 SCAR=24.8
Pod undocumented
53 0 my ($self,$file,$target) = @_;
54 0 ▶ if ($self->contains_file( $file )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->contains_file($file)) { } 0 0 0
55 0 ▶ open my $fh, '>', $target
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $target or croak("Couldn't create '${target}': $!") 0 0 0
56 or croak "Couldn't create '$target': $!";
57 0 binmode $fh;
58 0 print {$fh} $self->get_content($file);
59 } else {
60 0 croak "'$file' is not contained in '" . $self->directory . "'";
61 };
62 };
63  
64 1 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<Path::Class> to handle this issue.
70  
71 =head1 REPOSITORY
72  
73 The public repository of this module is
74 L<https://github.com/Corion/archive-merged>.
75  
76 =head1 SUPPORT
77  
78 The public support forum of this module is
79 L<https://perlmonks.org/>.
80  
81 =head1 BUG TRACKER
82  
83 Please report bugs in this module via the RT CPAN bug queue at
84 L<https://rt.cpan.org/Public/Dist/Display.html?Name=Archive-Merged>
85 or via mail to L<archive-merged-Bugs@rt.cpan.org>.
86  
87 =head1 AUTHOR
88  
89 Max Maischein C<corion@cpan.org>
90  
91 =head1 COPYRIGHT (c)
92  
93 Copyright 2015-2023 by Max Maischein C<corion@cpan.org>.
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<Archive::Tar>
104  
105 L<Archive::SevenZip::API::ArchiveTar>
106  
107 =cut
« Merged.pm ↑ Summary