blib/lib/EPUB/Parser/Util/Archive.pm

filter: Statementstmt 100% 84 / 84 Branchbran 71.4% 10 / 14 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 24 / 24 Podpod 0.0% 0 / 3 totaltotal 92.9% 119 / 128 SCAR 22.0
CC
9
Cov
95%
get_member_data
3.1
_next_member
3.1
get_members
2.0
CRAP 9.0
« blib/lib/EPUB/Parser/File/OPF.pm ↑ Summary blib/lib/EPUB/Parser/Util/EpubLoad.pm »
1 package EPUB::Parser::Util::Archive;
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use Smart::Args;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use Archive::Zip qw( AZ_OK );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub new {
9 14 ▶ args(
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
10 my $class => 'ClassName',
11 my $data => { isa => 'Archive::Zip' },
12 );
13  
14 14 bless { data => $data } => $class;
15 }
16  
17 sub get_member_data {
18 25 ▶ args(
Subroutine get_member_data: called CC=3 SCAR=11.2
Pod undocumented
19 my $self => 'Object',
20 my $file_path => 'Str',
21 );
22  
23 25 my $member = $self->{data}->memberNamed($file_path);
24 25 ▶ croak "$file_path not found" unless ($member);
Branch: 1 branch
BranchTrueFalseTotal
unless $member 0 25 25
25  
26 25 my ( $member_data, $AZ_status ) = $member->contents();
27 25 ▶ croak "$file_path: error Archive::Zip status = $AZ_status" if ($AZ_status != AZ_OK);
Branch: 1 branch
BranchTrueFalseTotal
if $AZ_status != 0 0 25 25
28  
29 25 return $member_data;
30  
31 }
32  
33 sub get_members {
34 11 ▶ my $self = shift;
Subroutine get_members: called CC=2 SCAR=7.0
Pod undocumented
35 11 ▶ my $args = shift || {};
Condition50%1/2
shift() || {}
l!l
110
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
36 11 $args->{zip} = $self;
37  
38 11 EPUB::Parser::Util::Archive::Iterator->new($args);
39 }
40  
41  
42 package EPUB::Parser::Util::Archive::Iterator;
43 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 14 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 14 ▶use Smart::Args;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 14 ▶use Archive::Zip qw( AZ_OK );
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 sub new {
50 11 ▶ args(
Subroutine new: called CC=1 SCAR=0.0
51 my $class => 'ClassName',
52 my $zip => { isa => 'EPUB::Parser::Util::Archive'},
53 my $files_path => 'ArrayRef[Str]',
54 );
55  
56 11 bless {
57 zip => $zip,
58 files_path => $files_path,
59 current_index => -1,
60 current_member => undef,
61 } => $class;
62
63 }
64  
65 sub size {
66 58 ▶ my $self = shift;
Subroutine size: called CC=1 SCAR=0.0
67 58 scalar @{$self->{files_path}};
68 }
69  
70 sub current_file_path {
71 66 ▶ my $self = shift;
Subroutine current_file_path: called CC=1 SCAR=0.0
72 66 $self->{files_path}->[$self->{current_index}];
73 }
74  
75 sub is_last {
76 52 ▶ my $self = shift;
Subroutine is_last: called CC=1 SCAR=0.0
77 52 $self->{current_index} == ( $self->size - 1 );
78 }
79  
80 sub reset {
81 3 ▶ my $self = shift;
Subroutine reset: called CC=1 SCAR=0.0
82 3 $self->{current_index} = -1;
83 3 $self->data(undef);
84 }
85  
86 sub first {
87 1 ▶ my $self = shift;
Subroutine first: called CC=1 SCAR=0.0
88 1 $self->reset;
89 1 $self->next;
90 }
91  
92 sub all {
93 1 ▶ my $self = shift;
Subroutine all: called CC=2 SCAR=6.9
94 1 $self->reset;
95 1 my @data;
96 1 ▶ while( my $member = $self->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $member = $self->next) 2 1 3
97 2 push @data, $member->data;
98 };
99  
100 1 return @data;
101 }
102  
103 sub next {
104 49 ▶ my $self = shift;
Subroutine next: called CC=2 SCAR=6.9
105 49 ▶ return if $self->is_last;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_last 8 41 49
106  
107 41 $self->_next_member;
108  
109 41 return $self;
110 }
111  
112 sub _next_member {
113 41 ▶ my $self = shift;
Subroutine _next_member: called CC=3 SCAR=11.2
114  
115 41 $self->{current_index}++;
116 41 my $member = $self->{zip}->{data}->memberNamed($self->current_file_path);
117 41 ▶ croak $self->current_file_path . ' not found' unless $member;
Branch: 1 branch
BranchTrueFalseTotal
unless $member 0 41 41
118  
119 41 my ( $member_data, $AZ_status ) = $member->contents();
120 41 ▶ croak $self->current_file_path . ": error Archive::Zip status = $AZ_status" if ($AZ_status != AZ_OK);
Branch: 1 branch
BranchTrueFalseTotal
if $AZ_status != 0 0 41 41
121  
122 41 $self->data($member_data);
123  
124 }
125  
126 sub data {
127 79 ▶ my $self = shift;
Subroutine data: called CC=2 SCAR=6.9
128 79 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 44 35 79
129 44 $self->{data} = shift;
130 }
131 79 $self->{data};
132 }
133  
134 14 ▶{ no warnings; *path = \&current_file_path; }
Subroutine BEGIN: called CC=1 SCAR=0.0
135  
136 14 1;
« blib/lib/EPUB/Parser/File/OPF.pm ↑ Summary blib/lib/EPUB/Parser/Util/EpubLoad.pm »