| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package EPUB::Parser::Util::Archive; | 
| 2 | 14 |  |  | 14 |  | 80 | use strict; | 
|  | 14 |  |  |  |  | 25 |  | 
|  | 14 |  |  |  |  | 540 |  | 
| 3 | 14 |  |  | 14 |  | 79 | use warnings; | 
|  | 14 |  |  |  |  | 24 |  | 
|  | 14 |  |  |  |  | 442 |  | 
| 4 | 14 |  |  | 14 |  | 75 | use Carp; | 
|  | 14 |  |  |  |  | 26 |  | 
|  | 14 |  |  |  |  | 1806 |  | 
| 5 | 14 |  |  | 14 |  | 17092 | use Smart::Args; | 
|  | 14 |  |  |  |  | 458924 |  | 
|  | 14 |  |  |  |  | 1176 |  | 
| 6 | 14 |  |  | 14 |  | 176 | use Archive::Zip qw( AZ_OK ); | 
|  | 14 |  |  |  |  | 31 |  | 
|  | 14 |  |  |  |  | 4028 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | sub new { | 
| 9 | 0 |  |  | 0 | 0 |  | args( | 
| 10 |  |  |  |  |  |  | my $class => 'ClassName', | 
| 11 |  |  |  |  |  |  | my $data => { isa => 'Archive::Zip' }, | 
| 12 |  |  |  |  |  |  | ); | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 0 |  |  |  |  |  | bless { data => $data } => $class; | 
| 15 |  |  |  |  |  |  | } | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub get_member_data { | 
| 18 | 0 |  |  | 0 | 0 |  | args( | 
| 19 |  |  |  |  |  |  | my $self      => 'Object', | 
| 20 |  |  |  |  |  |  | my $file_path => 'Str', | 
| 21 |  |  |  |  |  |  | ); | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 0 |  |  |  |  |  | my $member = $self->{data}->memberNamed($file_path); | 
| 24 | 0 | 0 |  |  |  |  | croak "$file_path not found" unless ($member); | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 0 |  |  |  |  |  | my ( $member_data, $AZ_status ) = $member->contents(); | 
| 27 | 0 | 0 |  |  |  |  | croak "$file_path: error Archive::Zip status = $AZ_status" if ($AZ_status != AZ_OK); | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 0 |  |  |  |  |  | return $member_data; | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | sub get_members { | 
| 34 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 35 | 0 |  | 0 |  |  |  | my $args = shift || {}; | 
| 36 | 0 |  |  |  |  |  | $args->{zip} = $self; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 0 |  |  |  |  |  | EPUB::Parser::Util::Archive::Iterator->new($args); | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | package EPUB::Parser::Util::Archive::Iterator; | 
| 43 | 14 |  |  | 14 |  | 86 | use strict; | 
|  | 14 |  |  |  |  | 29 |  | 
|  | 14 |  |  |  |  | 505 |  | 
| 44 | 14 |  |  | 14 |  | 75 | use warnings; | 
|  | 14 |  |  |  |  | 28 |  | 
|  | 14 |  |  |  |  | 491 |  | 
| 45 | 14 |  |  | 14 |  | 79 | use Carp; | 
|  | 14 |  |  |  |  | 28 |  | 
|  | 14 |  |  |  |  | 926 |  | 
| 46 | 14 |  |  | 14 |  | 75 | use Smart::Args; | 
|  | 14 |  |  |  |  | 27 |  | 
|  | 14 |  |  |  |  | 693 |  | 
| 47 | 14 |  |  | 14 |  | 73 | use Archive::Zip qw( AZ_OK ); | 
|  | 14 |  |  |  |  | 27 |  | 
|  | 14 |  |  |  |  | 6704 |  | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub new { | 
| 50 | 0 |  |  | 0 |  |  | args( | 
| 51 |  |  |  |  |  |  | my $class => 'ClassName', | 
| 52 |  |  |  |  |  |  | my $zip   => { isa => 'EPUB::Parser::Util::Archive'}, | 
| 53 |  |  |  |  |  |  | my $files_path => 'ArrayRef[Str]', | 
| 54 |  |  |  |  |  |  | ); | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 0 |  |  |  |  |  | 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 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 67 | 0 |  |  |  |  |  | scalar @{$self->{files_path}}; | 
|  | 0 |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | sub current_file_path { | 
| 71 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 72 | 0 |  |  |  |  |  | $self->{files_path}->[$self->{current_index}]; | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub is_last { | 
| 76 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 77 | 0 |  |  |  |  |  | $self->{current_index} == ( $self->size - 1 ); | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | sub reset { | 
| 81 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 82 | 0 |  |  |  |  |  | $self->{current_index} = -1; | 
| 83 | 0 |  |  |  |  |  | $self->data(undef); | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | sub first { | 
| 87 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 88 | 0 |  |  |  |  |  | $self->reset; | 
| 89 | 0 |  |  |  |  |  | $self->next; | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | sub all { | 
| 93 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 94 | 0 |  |  |  |  |  | $self->reset; | 
| 95 | 0 |  |  |  |  |  | my @data; | 
| 96 | 0 |  |  |  |  |  | while( my $member = $self->next ) { | 
| 97 | 0 |  |  |  |  |  | push @data, $member->data; | 
| 98 |  |  |  |  |  |  | }; | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 0 |  |  |  |  |  | return @data; | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | sub next { | 
| 104 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 105 | 0 | 0 |  |  |  |  | return if $self->is_last; | 
| 106 |  |  |  |  |  |  |  | 
| 107 | 0 |  |  |  |  |  | $self->_next_member; | 
| 108 |  |  |  |  |  |  |  | 
| 109 | 0 |  |  |  |  |  | return $self; | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | sub _next_member { | 
| 113 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 114 |  |  |  |  |  |  |  | 
| 115 | 0 |  |  |  |  |  | $self->{current_index}++; | 
| 116 | 0 |  |  |  |  |  | my $member = $self->{zip}->{data}->memberNamed($self->current_file_path); | 
| 117 | 0 | 0 |  |  |  |  | croak $self->current_file_path . ' not found' unless $member; | 
| 118 |  |  |  |  |  |  |  | 
| 119 | 0 |  |  |  |  |  | my ( $member_data, $AZ_status ) = $member->contents(); | 
| 120 | 0 | 0 |  |  |  |  | croak $self->current_file_path . ": error Archive::Zip status = $AZ_status" if ($AZ_status != AZ_OK); | 
| 121 |  |  |  |  |  |  |  | 
| 122 | 0 |  |  |  |  |  | $self->data($member_data); | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | } | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | sub data { | 
| 127 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 128 | 0 | 0 |  |  |  |  | if (@_) { | 
| 129 | 0 |  |  |  |  |  | $self->{data} = shift; | 
| 130 |  |  |  |  |  |  | } | 
| 131 | 0 |  |  |  |  |  | $self->{data}; | 
| 132 |  |  |  |  |  |  | } | 
| 133 |  |  |  |  |  |  |  | 
| 134 | 14 |  |  | 14 |  | 82 | { no warnings; *path = \¤t_file_path; } | 
|  | 14 |  |  |  |  | 35 |  | 
|  | 14 |  |  |  |  | 918 |  | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | 1; |