lib/Spreadsheet/Reader/ExcelXML/ZipReader.pm

filter: Statementstmt 100% 73 / 73 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 17 / 17 Podpod 50.0% 1 / 2 totaltotal 99.0% 99 / 100 CC 5 SCAR 3.9
CC
5
Cov
100%
DEMOLISH
3.0
extract_file
2.0
_build_zip_reader
2.0
CRAP 1.5
« lib/Spreadsheet/Reader/ExcelXML/Error.pm ↑ Summary lib/Spreadsheet/Reader/ExcelXML/SharedStrings.pm »
1 package Spreadsheet::Reader::ExcelXML::ZipReader;
2 16 our $AUTHORITY = 'cpan:JANDREW';
3 16 ▶use version; our $VERSION = version->declare('v0.16.8');
Subroutine BEGIN: called CC=1 SCAR=0.0
4 ###LogSD warn "You uncovered internal logging statements for Spreadsheet::Reader::ExcelXML::ZipReader-$VERSION";
5  
6 16 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use MooseX::HasDefaults::RO;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use Types::Standard qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
11 HasMethods Bool Str Enum
12 16 );#Int Num
13 16 ▶use Archive::Zip qw( AZ_OK );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 16 ▶use Capture::Tiny qw( capture_stderr );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 16 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 16 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 16 ▶use lib '../../../../lib',;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 ###LogSD with 'Log::Shiras::LogSpace';
19 ###LogSD use Log::Shiras::Telephone;
20  
21 16 ▶use Spreadsheet::Reader::ExcelXML::Types qw( IOFileType );
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 #########1 Public Attributes 3#########4#########5#########6#########7#########8#########9
24  
25 16 has file =>(
26 isa => IOFileType,
27 reader => 'get_file',
28 writer => 'set_file',
29 predicate => 'has_file',
30 clearer => 'clear_file',
31 coerce => 1,
32 trigger => \&_build_zip_reader,
33 handles => [ 'close' ],
34 );
35  
36 16 has file_type =>(
37 isa => Enum[ 'zip' ],
38 reader => 'get_file_type',
39 default => 'zip',
40 );
41  
42 16 has workbook_inst =>(
43 isa => 'Spreadsheet::Reader::ExcelXML::Workbook',
44 handles =>[ qw( set_error )],
45 writer => 'set_workbook_inst',
46 );
47  
48 #########1 Public Methods 3#########4#########5#########6#########7#########8#########9
49  
50 106 ▶sub extract_file{
Subroutine extract_file: called CC=2 SCAR=6.9
Pod documented
51 106 my ( $self, $file ) = ( @_ );
52 ###LogSD my $phone = Log::Shiras::Telephone->new( name_space =>
53 ###LogSD $self->get_all_space . '::extract_file', );
54 ###LogSD $phone->talk( level => 'trace', message =>[
55 ###LogSD 'Arrived at extract_file for the workbook general settings:', $file ] );
56 106 my $zip_member = $self->_member_named( $file );
57 ###LogSD $phone->talk( level => 'debug', message =>[ 'zip member:', $zip_member ] );
58 106 ▶ if( $zip_member ){
Branch: 1 branch
BranchTrueFalseTotal
if ($zip_member) { } 105 1 106
59 105 my $workbook_fh = IO::File->new_tmpfile;
60 105 $workbook_fh->binmode();
61 105 $zip_member->extractToFileHandle( $workbook_fh );
62 105 $workbook_fh->seek( 0, 0 );
63 ###LogSD $phone->talk( level => 'debug', message =>[
64 ###LogSD 'succesfully built the zip sub file:', $workbook_fh ] );
65 105 return $workbook_fh;
66 }else{
67 ###LogSD $phone->talk( level => 'debug', message =>[ "no zip file for: $file" ] );
68 1 return undef;
69 }
70 }
71  
72 #########1 Private Attributes 3#########4#########5#########6#########7#########8#########9
73  
74 16 has _loaded =>(
75 isa => Bool,
76 writer => '_good_load',
77 reader => 'loaded_correctly',
78 default => 0,
79 );
80  
81 16 has _zip_reader =>(
82 isa => 'Archive::Zip',
83 reader => '_get_zip_parser',
84 writer => '_set_zip_parser',
85 predicate => '_has_zip_parser',
86 clearer => '_clear_zip_parser',
87 handles =>{
88 _member_named => 'memberNamed',
89 },
90 );
91  
92 16 has _read_unique_bits =>(
93 isa => Bool,
94 reader => '_get_unique_bits',
95 writer => '_need_unique_bits',
96 clearer => '_clear_read_unique_bits',
97 default => 1,
98 );
99  
100 #########1 Private Methods 3#########4#########5#########6#########7#########8#########9
101  
102 19 ▶sub _build_zip_reader{
Subroutine _build_zip_reader: called CC=2 SCAR=6.9
103 19 my( $self, $file ) = @_;
104 ###LogSD my $phone = Log::Shiras::Telephone->new( name_space =>
105 ###LogSD $self->get_all_space . '::ZipReader::_build_zip_reader', );
106 ###LogSD $phone->talk( level => 'debug', message => [
107 ###LogSD "turning a file handle into a zip reader", $file, ] );
108  
109 # Read the XLSX zip file and catch any errors (other zip file sanity tests go here)
110 19 my $workbook_file = Archive::Zip->new();
111 19 my $read_state;
112 19 $file->seek( 0, 0 );# Reset in case an XML read attempt was made
113 19 ▶ my $error_message = capture_stderr{ $read_state = $workbook_file->readFromFileHandle($file) };
Subroutine __ANON__: called CC=1 SCAR=0.0
114 ###LogSD $phone->talk( level => 'debug', message => [
115 ###LogSD "Error message is:", $error_message ] );
116 19 ▶ if( $read_state != AZ_OK ){
Branch: 1 branch
BranchTrueFalseTotal
if ($read_state != 0) { } 1 18 19
117 ###LogSD $phone->talk( level => 'warn', message =>[
118 ###LogSD "Failed to open the file as a zip file" ] );
119 1 $self->set_error( "|$file| won't open as a zip file because: $error_message" );
120 1 $self->clear_file;
121 1 $self->_clear_zip_parser;
122 }else{
123 ###LogSD $phone->talk( level => 'debug', message =>[
124 ###LogSD "Certified this as a zip file" ] );
125 18 $self->_set_zip_parser( $workbook_file );
126 18 $self->_good_load( 1 );
127 }
128 }
129  
130 18 ▶sub DEMOLISH{
Subroutine DEMOLISH: called CC=3 SCAR=11.0
Pod undocumented
131 18 my ( $self ) = @_;
132 ###LogSD my $phone = Log::Shiras::Telephone->new( name_space =>
133 ###LogSD $self->get_all_space . '::ZipReader::DEMOLISH', );
134 ###LogSD $phone->talk( level => 'debug', message => [
135 ###LogSD "clearing the zip reader for log space:", $self->get_log_space, ] );
136  
137 # Clear the reader
138 18 ▶ if( $self->_has_zip_parser ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_zip_parser) 17 1 18
139 ###LogSD $phone->talk( level => 'debug', message =>[ "Clearing the zip parser", ] );
140 17 $self->_clear_zip_parser;
141 }
142  
143 # Clear the file
144 18 ▶ if( $self->has_file ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_file) 17 1 18
145 ###LogSD $phone->talk( level => 'debug', message =>[ "Closing and disconnecting the file handle for the zip parser", ] );
146 17 $self->clear_file;
147 }
148 }
149  
150 #########1 Phinish 3#########4#########5#########6#########7#########8#########9
151  
152 16 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
153  
154 16 1;
155  
156 #########1 Documentation 3#########4#########5#########6#########7#########8#########9
157 __END__
« lib/Spreadsheet/Reader/ExcelXML/Error.pm ↑ Summary lib/Spreadsheet/Reader/ExcelXML/SharedStrings.pm »