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 CC 9 SCAR 4.9
CC
9
Cov
95%
get_member_data
3.1
_next_member
3.1
get_members
2.0
CRAP 1.6
« Parser.pm ↑ Summary Parser/File/Navi.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 14 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
9 14 args(
10 my $class => 'ClassName',
11 my $data => { isa => 'Archive::Zip' },
12 );
13  
14 14 bless { data => $data } => $class;
15 }
16  
17 25 ▶sub get_member_data {
Subroutine get_member_data: called CC=3 SCAR=11.2
Pod undocumented
18 25 args(
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 11 ▶sub get_members {
Subroutine get_members: called CC=2 SCAR=7.0
Pod undocumented
34 11 my $self = shift;
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 11 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
50 11 args(
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 58 ▶sub size {
Subroutine size: called CC=1 SCAR=0.0
66 58 my $self = shift;
67 58 scalar @{$self->{files_path}};
68 }
69  
70 66 ▶sub current_file_path {
Subroutine current_file_path: called CC=1 SCAR=0.0
71 66 my $self = shift;
72 66 $self->{files_path}->[$self->{current_index}];
73 }
74  
75 52 ▶sub is_last {
Subroutine is_last: called CC=1 SCAR=0.0
76 52 my $self = shift;
77 52 $self->{current_index} == ( $self->size - 1 );
78 }
79  
80 3 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
81 3 my $self = shift;
82 3 $self->{current_index} = -1;
83 3 $self->data(undef);
84 }
85  
86 1 ▶sub first {
Subroutine first: called CC=1 SCAR=0.0
87 1 my $self = shift;
88 1 $self->reset;
89 1 $self->next;
90 }
91  
92 1 ▶sub all {
Subroutine all: called CC=2 SCAR=6.9
93 1 my $self = shift;
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 49 ▶sub next {
Subroutine next: called CC=2 SCAR=6.9
104 49 my $self = shift;
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 41 ▶sub _next_member {
Subroutine _next_member: called CC=3 SCAR=11.2
113 41 my $self = shift;
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 79 ▶sub data {
Subroutine data: called CC=2 SCAR=6.9
127 79 my $self = shift;
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;
« Parser.pm ↑ Summary Parser/File/Navi.pm »