lib/Spreadsheet/Reader/ExcelXML.pm

filter: Statementstmt 83.9% 89 / 106 Branchbran 52.9% 18 / 34 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 20 / 20 Podpod 50.0% 1 / 2 totaltotal 77.7% 133 / 171 CC 26 SCAR 29.4
CC
26
Cov
76%
__ANON__
49.1
import
9.7
parse
5.2
CRAP 18.9
« lib/Spreadsheet/Reader/ExcelXML/WorksheetToRow.pm ↑ Summary lib/Spreadsheet/Reader/ExcelXML/XMLReader/PositionStyles.pm »
1 package Spreadsheet::Reader::ExcelXML;
2 15 our $AUTHORITY = 'cpan:JANDREW';
3 15 ▶use version 0.77; 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-$VERSION";
5  
6 15 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use MooseX::HasDefaults::RO;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Types::Standard qw( is_HashRef is_Object );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Clone 'clone';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 ###LogSD use B::Deparse;
13 ###LogSD my $deparser = B::Deparse->new;
14  
15 15 ▶use MooseX::ShortCut::BuildInstance 1.040 qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
16 build_instance should_re_use_classes set_args_cloning
17 15 );
18 15 should_re_use_classes( 1 );
19 15 set_args_cloning ( 0 );
20 ###LogSD use Log::Shiras::Telephone v0.48.0;
21 15 ▶use lib '../../../../lib',;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 15 ▶use Spreadsheet::Reader::ExcelXML::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 15 ▶use Spreadsheet::Reader::ExcelXML::Workbook;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 15 ▶use Spreadsheet::Reader::Format v0.6.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 15 ▶use Spreadsheet::Reader::Format::FmtDefault;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 15 ▶use Spreadsheet::Reader::Format::ParseExcelFormatStrings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 15 ▶use Spreadsheet::Reader::ExcelXML::Types qw( XLSXFile IOFileType );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 ###LogSD with 'Log::Shiras::LogSpace';
29  
30 #########1 Dispatch Tables and data 4#########5#########6#########7#########8#########9
31  
32 15 my $attribute_defaults ={
33 error_inst =>{
34 package => 'ErrorInstance',
35 superclasses => ['Spreadsheet::Reader::ExcelXML::Error'],
36 should_warn => 0,
37 },
38 formatter_inst =>{
39 package => 'FormatInstance',
40 superclasses => [ 'Spreadsheet::Reader::Format::FmtDefault' ],
41 add_roles_in_sequence =>[qw(
42 Spreadsheet::Reader::Format::ParseExcelFormatStrings
43 Spreadsheet::Reader::Format
44 )],
45 },
46 count_from_zero => 1,
47 file_boundary_flags => 1,
48 empty_is_end => 0,
49 values_only => 0,
50 from_the_edge => 1,
51 group_return_type => 'instance',
52 empty_return_type => 'empty_string',
53 cache_positions =>{# Test this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
54 shared_strings_interface => 5242880,# 5 MB
55 styles_interface => 5242880,# 5 MB
56 worksheet_interface => 2097152,# 2 MB
57 },
58 show_sub_file_size => 0,
59 spread_merged_values => 0,
60 skip_hidden => 0,
61 spaces_are_empty => 0,
62 merge_data => 1,
63 column_formats => 1,
64  
65 };
66 15 my $flag_settings ={
67 alt_default =>{
68 values_only => 1,
69 count_from_zero => 0,
70 empty_is_end => 1,
71 },
72 just_the_data =>{
73 count_from_zero => 0,
74 values_only => 1,
75 empty_is_end => 1,
76 group_return_type => 'value',
77 from_the_edge => 0,
78 empty_return_type => 'undef_string',
79 spaces_are_empty => 1,
80 merge_data => 0,
81 column_formats => 0,
82 },
83 just_raw_data =>{
84 count_from_zero => 0,
85 values_only => 1,
86 empty_is_end => 1,
87 group_return_type => 'unformatted',
88 from_the_edge => 0,
89 empty_return_type => 'undef_string',
90 spaces_are_empty => 1,
91 merge_data => 0,
92 column_formats => 0,
93 },
94 like_ParseExcel =>{
95 count_from_zero => 1,
96 group_return_type => 'instance',
97 },
98 debug =>{
99 error_inst =>{
100 superclasses => ['Spreadsheet::Reader::ExcelXML::Error'],
101 package => 'ErrorInstance',
102 should_warn => 1,
103 },
104 show_sub_file_size => 1,
105 },
106 lots_of_ram =>{
107 cache_positions =>{
108 shared_strings_interface => 209715200,# 200 MB
109 styles_interface => 209715200,# 200 MB
110 worksheet_interface => 209715200,# 200 MB
111 },
112 },
113 less_ram =>{
114 cache_positions =>{
115 shared_strings_interface => 10240,# 10 KB
116 styles_interface => 10240,# 10 KB
117 worksheet_interface => 1024,# 1 KB
118 },
119 },
120 };
121 15 my $delay_till_build = [qw( formatter_inst )];
122  
123 #########1 Public Methods 3#########4#########5#########6#########7#########8#########9
124  
125 ###LogSD sub get_class_space{ 'Top' }
126  
127 20 ▶sub import{# Flags handled here!
Subroutine import: called CC=7 SCAR=22.7
128 20 my ( $self, @flag_list ) = @_;
129 #~ print "Made it to import\n";
130 #~ if( scalar( @flag_list ) ){
131 20 for my $flag ( @flag_list ){
132 #~ print "Arrived at import with flag: $flag\n";
133 9 ▶ if( $flag =~ /^:(\w*)$/ ){# Handle text based flags
Branch: 2 branches
BranchTrueFalseTotal
if ($flag =~ /^:(\w*)$/) { } 8 1 9
elsif ($flag =~ /^v?\d+\.?\d*/) { } 0 1 1
134 8 my $default_choice = $1;
135 #~ print "Attempting to change the default group type to: $default_choice\n";
136 8 ▶ if( exists $flag_settings->{$default_choice} ){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $flag_settings->{$default_choice}) { } 8 0 8
137 8 for my $attribute ( keys %{$flag_settings->{$default_choice}} ){
138 #~ print "Changing flag -$attribute- to:" . Dumper( $flag_settings->{$default_choice}->{$attribute} );
139 30 $attribute_defaults->{$attribute} = $flag_settings->{$default_choice}->{$attribute};
140 }
141 }else{
142 0 confess "No settings available for the flag: $flag";
143 }
144 }elsif( $flag =~ /^v?\d+\.?\d*/ ){# Version check may wind up here
145 #~ print "Running version check on version: $flag\n";
146 0 my $result = $VERSION <=> version->parse( $flag );
147 #~ print "Tested against version -$VERSION- gives result: $result\n";
148 0 ▶ if( $result < 0 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($result < 0) 0 0 0
149 0 confess "Version -$flag- required - the installed version is: $VERSION";
150 }
151 }else{
152 1 confess "Passed attribute default flag -$flag- does not comply with the correct format";
153 }
154 }
155 #~ }
156 #~ print "Finished import\n";
157 }
158  
159 11 ▶sub parse{
Subroutine parse: called CC=5 SCAR=16.4
Pod documented
160  
161 11 my ( $self, $file, $formatter ) = @_;
162 ###LogSD my $phone = Log::Shiras::Telephone->new( name_space =>
163 ###LogSD $self->get_all_space . '::parse', );
164 ###LogSD $phone->talk( level => 'info', message =>[
165 ###LogSD "Arrived at parse for:", $file,
166 ###LogSD (($formatter) ? "with formatter: $formatter" : '') ] );
167  
168 # Test the file
169 11 ▶ if( XLSXFile->check( $file ) ){
Branch: 2 branches
BranchTrueFalseTotal
if (&XLSXFile()->check($file)) { } 9 2 11
elsif (&IOFileType()->check($file)) { } 0 2 2
170 ###LogSD $phone->talk( level => 'info', message =>[ "This is an xlsx file: $file" ] );
171 }elsif( IOFileType->check( $file ) ){
172 ###LogSD $phone->talk( level => 'info', message =>[ "This is a file handle:", $file ] );
173 }else{
174 2 $self->set_error( "Value \"$file\" did not pass type constraint \"IOFileType\"" );
175 2 return undef;
176 }
177  
178 # Load the formatter
179 9 ▶ if( $formatter ){
Branch: 1 branch
BranchTrueFalseTotal
if ($formatter) 0 9 9
180 0 $self->set_formatter_inst( $formatter );
181 ###LogSD $phone->talk( level => 'info', message =>[ "Formatter added" ] );
182 }
183  
184 9 $self->set_file( $file );
185 ###LogSD $phone->talk( level => 'info', message =>[ "Build workbook attempt complete", $self->file_opened ] );
186 9 ▶ return $self->file_opened ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->file_opened ? : 8 1 9
187 }
188  
189 #########1 Private Attributes 3#########4#########5#########6#########7#########8#########9
190  
191 15 has _workbook =>(
192 isa => 'Spreadsheet::Reader::ExcelXML::Workbook',
193 predicate => '_has_workbook',
194 writer => '_set_workbook',
195 clearer => '_clear_the_workbook',
196 handles => [qw(
197 error set_error clear_error set_warnings
198 should_spew_longmess spewing_longmess if_warn has_error
199 get_error_inst has_error_inst set_formatter_inst get_excel_region
200  
201 get_formatter_region has_target_encoding get_target_encoding set_workbook_for_formatter
202 set_target_encoding set_european_first set_date_behavior get_defined_conversion
203 set_defined_excel_formats change_output_encoding
204 set_formatter_cache_behavior parse_excel_format_string
205  
206 set_file counting_from_zero boundary_flag_setting spreading_merged_values
207 is_empty_the_end get_values_only starts_at_the_edge get_group_return_type
208 get_empty_return_type cache_positions get_cache_size has_cache_size
209 should_skip_hidden are_spaces_empty
210  
211 worksheet worksheets build_workbook demolish_the_workbook
212  
213 file_name file_opened get_epoch_year has_epoch_year
214 get_sheet_names get_sheet_name sheet_count get_sheet_info
215 get_rel_info get_id_info get_worksheet_names worksheet_name
216 worksheet_count get_chartsheet_names chartsheet_name chartsheet_count
217 creator modified_by date_created date_modified
218 in_the_list start_at_the_beginning
219 )],
220 );
221 #~ get_shared_string start_the_ss_file_over has_shared_strings_interface
222 #~ has_styles_interface get_format
223  
224 #########1 Private Methods 3#########4#########5#########6#########7#########8#########9
225  
226 21 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=15 SCAR=38.9
227 21 my ( $orig, $class, @args ) = @_;
228 0 ▶ my %args = is_HashRef( $args[0] ) ? %{$args[0]} : @args;
Branch: 1 branch
BranchTrueFalseTotal
&is_HashRef($args[0]) ? : 0 21 21
229 ###LogSD $args{log_space} //= 'ExcelXML';
230 ###LogSD my $class_space = __PACKAGE__->get_class_space;
231 ###LogSD my $log_space = $args{log_space} . "::$class_space" . '::_hidden::BUILDARGS';
232 ###LogSD my $phone = Log::Shiras::Telephone->new( name_space => $log_space, );
233 ###LogSD $phone->talk( level => 'trace', message =>[
234 ###LogSD 'Arrived at BUILDARGS with: ', @args, ] );# caller(3), caller(4), caller(5)
235  
236 # Handle depricated cache_positions
237 #~ print longmess( Dumper( %args ) );
238 21 ▶ if( exists $args{cache_positions} ){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"cache_positions"}) 0 21 21
239 ###LogSD $phone->talk( level => 'trace', message =>[
240 ###LogSD "The user did pass a value to cache_positions as:", $args{cache_positions}] );
241 0 ▶ if( !is_HashRef( $args{cache_positions} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (&is_HashRef($args{"cache_positions"})) 0 0 0
242 0 warn "Passing a boolean value to the attribute 'cache_positions' is depricated since v0.40.2 - the input will be converted per the documentation";
243 $args{cache_positions} = !$args{cache_positions} ?
244 $flag_settings->{big_file}->{cache_positions} :
245 0 ▶ $attribute_defaults->{cache_positions};
Branch: 1 branch
BranchTrueFalseTotal
!$args{'cache_positions'} ? : 0 0 0
246 }
247  
248 #scrub cache_positions
249 0 for my $passed_key ( keys %{$args{cache_positions}} ){
250 0 ▶ if( !exists $attribute_defaults->{cache_positions}->{$passed_key} ){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $attribute_defaults->{"cache_positions"}{$passed_key}) 0 0 0
251 0 warn "Passing a cache position for '$passed_key' but that is not allowed";
252 }
253 }
254 0 for my $stored_key ( keys %{$attribute_defaults->{cache_positions}} ){
255 0 ▶ if( !exists $args{cache_positions}->{$stored_key} ){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{"cache_positions"}{$stored_key}) 0 0 0
256 0 warn "Passed cache positions are missing key => values for key: $stored_key";
257 }
258 }
259 }
260  
261 # Add any defaults
262 ###LogSD $phone->talk( level => 'trace', message =>[
263 ###LogSD "Processing possible default values", $attribute_defaults ] );
264 21 for my $key ( keys %$attribute_defaults ){
265 ###LogSD $phone->talk( level => 'trace', message =>[
266 ###LogSD "Processing possible default for -$key- with value:", $attribute_defaults->{$key} ] );
267 336 ▶ if( exists $args{$key} ){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{$key}) { } 24 312 336
268 ###LogSD $phone->talk( level => 'trace', message =>[
269 ###LogSD "Found user defined -$key- with value(s): ", $args{$key} ] );
270 }else{
271 ###LogSD $phone->talk( level => 'trace', message =>[
272 ###LogSD "Setting default -$key- with value(s): ", $attribute_defaults->{$key} ] );
273 312 $args{$key} = clone( $attribute_defaults->{$key} );
274 }
275 }
276  
277 # Build object instances as needed
278 21 for my $key ( keys %args ){
279 ###LogSD $phone->talk( level => 'trace', message =>[
280 ###LogSD "Checking if an instance needs built for key: $key" ] );
281 345 ▶ if( $key =~ /_inst$/ and !is_Object( $args{$key} ) and is_HashRef( $args{$key} ) ){
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /_inst$/ and not &is_Object($args{$key}) and &is_HashRef($args{$key})) 42 303 345
Condition66%4/6
$key =~ /_inst$/ and not &is_Object($args{$key}) and &is_HashRef($args{$key})
!ll&&!rl&&r
303042
$key =~ /_inst$/ and not &is_Object($args{$key})
!ll&&!rl&&r
303042
MC/DC33%1/3
$key =~ /_inst$/ and not &is_Object($args{$key}) and &is_HashRef($args{$key})
$key =~ /_inst$/ not &is_Object($args{$key}) &is_HashRef($args{$key})
Truth table50%2/4
A and not(B) and C
A= $key =~ /_inst$/B= not &is_Object($args{$key})C= &is_HashRef($args{$key})
ABCresult
0XX0
10X0
1100
1111
282 # Import log_space as needed
283 ###LogSD if( exists $args{log_space} and $args{log_space} ){
284 ###LogSD $args{$key}->{log_space} = $args{log_space};
285 ###LogSD }
286 ###LogSD $phone->talk( level => 'trace', message =>[
287 ###LogSD "Key -$key- requires an instance built from:", $args{$key} ] );
288 42 $args{$key} = build_instance( $args{$key} );
289 }
290 }
291  
292 ###LogSD $phone->talk( level => 'trace', message =>[
293 ###LogSD "Final BUILDARGS:", %args ] );
294 21 my $workbook = Spreadsheet::Reader::ExcelXML::Workbook->new( %args );
295 ###LogSD $phone->talk( level => 'trace', message =>[
296 ###LogSD "Assigning the built workbook to the _workbook attribute with: ", $deparser->coderef2text( $orig ),
297 ###LogSD "..with workboook: ", $workbook->dump ] );
298 21 return $class->$orig(
299 _workbook => $workbook,
300 ###LogSD log_space => $args{log_space}
301 );
302 15 };
303  
304 22 ▶sub DEMOLISH{
Subroutine DEMOLISH: called CC=2 SCAR=6.9
Pod undocumented
305 22 my ( $self ) = @_;
306 ###LogSD my $phone = Log::Shiras::Telephone->new( name_space =>
307 ###LogSD $self->get_all_space . '::_hidden::DEMOLISH', );
308 ###LogSD $phone->talk( level => 'debug', message =>[
309 ###LogSD "Forcing Non-recursive garbage collection on recursive stuff" ] );
310 22 ▶ if( $self->_has_workbook ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_workbook) 21 1 22
311 ###LogSD $phone->talk( level => 'debug', message =>[
312 ###LogSD "Need to demolish the workbook" ] );
313 21 $self->demolish_the_workbook;
314 ###LogSD $phone->talk( level => 'debug', message =>[
315 ###LogSD "Clearing the attribute" ] );
316 21 $self->_clear_the_workbook;
317 }
318 }
319  
320 #########1 Phinish 3#########4#########5#########6#########7#########8#########9
321  
322 15 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
323 15 __PACKAGE__->meta->make_immutable;
324  
325 15 1;
326  
327 #########1 Documentation 3#########4#########5#########6#########7#########8#########9
328 __END__
« lib/Spreadsheet/Reader/ExcelXML/WorksheetToRow.pm ↑ Summary lib/Spreadsheet/Reader/ExcelXML/XMLReader/PositionStyles.pm »