File Coverage

blib/lib/Spreadsheet/ParseExcel/Stream.pm
Criterion Covered Total %
statement 18 25 72.0
branch 4 12 33.3
condition 2 2 100.0
subroutine 4 5 80.0
pod 1 3 33.3
total 29 47 61.7


line stmt bran cond sub pod time code
1             package Spreadsheet::ParseExcel::Stream;
2              
3 8     8   269471 use strict;
  8         26  
  8         299  
4 8     8   41 use warnings;
  8         293  
  8         3520  
5              
6             our $VERSION = '0.11';
7              
8             sub new {
9              
10 8     8 1 107 my ($class, $file, $opts) = @_;
11 8   100     57 $opts ||= {};
12 8         19 my $type = $opts->{Type};
13              
14 8 50       31 if ($type) {
15 0 0       0 return $class->xls($file, $opts) if $type =~ /^xls$/i;
16 0 0       0 return $class->xlsx($file, $opts) if $type =~ /^xlsx$/i;
17 0         0 die "Can not parse file $file of type $type";
18             }
19              
20 8 50       428 open(my $fh, "<", $file) or die "Failed to open $file: $!";
21 8         172 my $cnt = read($fh, my $pk, 4);
22 8         110 close $fh;
23 8 50       37 die "Unable to read header from $file" unless $cnt == 4;
24              
25 8 50       34 return $class->xlsx($file, $opts) if $pk eq "PK\003\004";
26 8         66 return $class->xls($file, $opts);
27             }
28              
29             sub xls {
30 8     8 0 21 my ($class, $file, $opts) = @_;
31 8         5359 require Spreadsheet::ParseExcel::Stream::XLS;
32 0           return Spreadsheet::ParseExcel::Stream::XLS->new($file, $opts);
33             }
34              
35             sub xlsx {
36 0     0 0   my ($class, $file, $opts) = @_;
37 0           require Spreadsheet::ParseExcel::Stream::XLSX;
38 0           return Spreadsheet::ParseExcel::Stream::XLSX->new($file, $opts);
39             }
40              
41             1;
42              
43             __END__