lib/Spreadsheet/Reader/ExcelXML/Types.pm

filter: Statementstmt 96.6% 115 / 119 Branchbran 46.6% 14 / 30 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 31 / 31 Podpod n/a totaltotal 87.0% 161 / 185 CC 12 SCAR 10.1
CC
12
Cov
86%
__ANON__
9.5
__ANON__
4.9
__ANON__
3.1
CRAP 2.7
« lib/Spreadsheet/Reader/ExcelXML/Row.pm ↑ Summary lib/Spreadsheet/Reader/ExcelXML/XMLReader/NamedSharedStrings.pm »
1 package Spreadsheet::Reader::ExcelXML::Types;
2 44 our $AUTHORITY = 'cpan:JANDREW';
3 44 ▶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::Types-$VERSION";
5  
6 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 44 ▶use Type::Utils -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 44 ▶use Type::Library 1.000
Subroutine BEGIN: called CC=1 SCAR=0.0
10 44 -base,
11 -declare => qw(
12 XMLFile XLSXFile CellID
13 IOFileType ErrorString SubString
14 SpecialZeroScientific SpecialOneScientific SpecialTwoScientific
15 SpecialThreeScientific SpecialFourScientific SpecialFiveScientific
16 SpecialDecimal
17 44 );
18 44 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 44 ▶BEGIN{ extends "Types::Standard" };
Subroutine BEGIN: called CC=1 SCAR=0.0
20 my $try_xs =
21 exists($ENV{PERL_TYPE_TINY_XS}) ? !!$ENV{PERL_TYPE_TINY_XS} :
22 exists($ENV{PERL_ONLY}) ? !$ENV{PERL_ONLY} :
23 44 ▶ 1;
Branch: 2 branches
BranchTrueFalseTotal
exists $ENV{'PERL_TYPE_TINY_XS'} ? : 44 0 44
exists $ENV{'PERL_ONLY'} ? : 0 0 0
24 44 ▶if( $try_xs and exists $INC{'Type/Tiny/XS.pm'} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($try_xs and exists $INC{"Type/Tiny/XS.pm"}) 0 44 44
Condition33%1/3
$try_xs and exists $INC{"Type/Tiny/XS.pm"}
!ll&&!rl&&r
4400
MC/DC0%0/2
$try_xs and exists $INC{"Type/Tiny/XS.pm"}
$try_xs exists $INC{"Type/Tiny/XS.pm"}
Truth table33%1/3
A and B
A= $try_xsB= exists $INC{"Type/Tiny/XS.pm"}
ABresult
0X0
100
111
25 0 eval "use Type::Tiny::XS 0.010";
26 0 ▶ if( $@ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
27 0 die "You have loaded Type::Tiny::XS but versions prior to 0.010 will cause this module to fail";
28 }
29 }
30  
31 #########1 Package Variables 3#########4#########5#########6#########7#########8#########9
32  
33  
34  
35 #########1 Type Library 3#########4#########5#########6#########7#########8#########9
36  
37 declare XMLFile,
38 as Str,
39 74 ▶ where{ $_ =~ /\.(xml|rels)$/i and -r $_},
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /\.(xml|rels)$/i and -r $_ 52 22 74
40 1 ▶ message{
Subroutine __ANON__: called CC=3 SCAR=16.0
41 1 ▶ ( $_ !~ /\.(xml|rels)$/i ) ?
Branch: 2 branches
BranchTrueFalseTotal
!($_ =~ /\.(xml|rels)$/i) ? : 1 0 1
!(-r $_) ? : 0 0 0
42 "The string -$_- does not have an xml file extension" :
43 ( !-r $_ ) ?
44 "Could not find / read the file: $_" :
45 'No value passed to the XMLFile test';
46 44 };
47  
48 declare XLSXFile,
49 as Str,
50 117 ▶ where{ $_ =~ /\.x(ls(x|m)|ml)$/i and -r $_ },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /\.x(ls(x|m)|ml)$/i and -r $_ 109 8 117
51 3 ▶ message{
Subroutine __ANON__: called CC=6 SCAR=22.6
52 3 my $test = $_;
53 3 ▶ my $return =
Branch: 5 branches
BranchTrueFalseTotal
!defined($test) ? : 0 3 3
ref $test ? : 2 1 3
!($test =~ /\.x(ls(x|m)|ml)$/i) ? : 1 0 1
-r $test ? : 0 0 0
$test ? : 0 0 0
54 ( !defined $test ) ?
55 "Empty filename" :
56 ( ref $test ) ?
57 "'" . $test . "' is not a string value" :
58 ( $test !~ /\.x(ls(x|m)|ml)$/i ) ?
59 "The string -$test- does not have an xlsx|xlsm|xml file extension" :
60 ( -r $test) ?
61 "Could not find / read the file: $test" :
62 "Unmanageable value '" . ($test ? $test : '' ) . "' passed" ;
63 3 return $return;
64 44 };
65  
66 44 declare IOFileType,
67 as InstanceOf[ 'IO::File' ];#, 'File::Temp'
68  
69 coerce IOFileType,
70 from GlobRef,
71 29 ▶ via{ my $fh = bless( $_, 'IO::File' );
Subroutine __ANON__: called CC=1 SCAR=0.0
72 29 $fh->binmode();
73 29 return $fh; };
74  
75 coerce IOFileType,
76 from XMLFile,
77 51 ▶ via{ my $fh = IO::File->new( $_, 'r' );
Subroutine __ANON__: called CC=1 SCAR=0.0
78 51 $fh->binmode();
79 51 return $fh; };
80  
81 coerce IOFileType,
82 from XLSXFile,
83 19 ▶ via{ my $fh = IO::File->new( $_, 'r' );
Subroutine __ANON__: called CC=1 SCAR=0.0
84 19 $fh->binmode();
85 19 return $fh; };
86  
87 44 declare CellID,
88 as StrMatch[ qr/^[A-Z]{1,3}[1-9]\d*$/ ];
89  
90 44 declare SubString,
91 as Str;
92  
93 declare ErrorString,
94 as SubString,
95 191 ▶ where{ $_ !~ /\)\n;/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
96  
97 coerce SubString,
98 from Object,
99 2 ▶ via{
Subroutine __ANON__: called CC=3 SCAR=11.3
100 2 my $object = $_;
101 2 ▶ if( $object->can( 'as_string' ) ){
Branch: 2 branches
BranchTrueFalseTotal
if ($object->can('as_string')) { } 1 1 2
elsif ($object->can('message')) { } 1 0 1
102 1 return $object->as_string;
103 }elsif( $object->can( 'message' ) ){
104 1 return $object->message;
105 }
106 0 return $object;
107 44 };
108  
109 coerce ErrorString,
110 from SubString->coercibles,
111 2 ▶ via{
Subroutine __ANON__: called CC=1 SCAR=0.0
112 2 my $tmp = to_SubString($_);
113 2 $tmp =~ s/\)\n;/\);/g;
114 2 return $tmp;
115 44 };
116  
117 declare SpecialZeroScientific,
118 as Str,
119 13 ▶ where{ return $_ =~ /^\-?[0-9]+E-?\d{2,50}/i };#print "--$_\n";
Subroutine __ANON__: called CC=1 SCAR=0.0
120  
121 coerce SpecialZeroScientific,
122 from Str,
123 7 ▶ via{
Subroutine __ANON__: called CC=1 SCAR=0.0
124 7 my $string = $_;
125 7 $string =~ /([\-\d\.]+)[Ee](-)?(\d+)/i;#
126 #~ print "$1\n";
127 #~ print "$2\n";
128 #~ print "$3\n";
129 7 my $return = sprintf '%.0f', $1;
130 #~ print "$return\n";
131 7 $return .= 'E' . sprintf '%s%02d', $2, $3;
132 #~ print "$return\n";
133 7 return $return;
134 44 };
135  
136 declare SpecialOneScientific,
137 as Str,
138 5 ▶ where{ return $_ =~ /^\-?[0-9]+\.\dE-?\d{2,50}/i };#print "--$_\n";
Subroutine __ANON__: called CC=1 SCAR=0.0
139  
140 coerce SpecialOneScientific,
141 from Str,
142 3 ▶ via{
Subroutine __ANON__: called CC=1 SCAR=0.0
143 3 my $string = $_;
144 3 $string =~ /([\-\d\.]+)[Ee](-)?(\d+)/i;#
145 #~ print "$1\n";
146 #~ print "$2\n";
147 #~ print "$3\n";
148 3 my $return = sprintf '%.1f', $1;
149 #~ print "$return\n";
150 3 $return .= 'E' . sprintf '%s%02d', $2, $3;
151 #~ print "$return\n";
152 3 return $return;
153 44 };
154  
155 declare SpecialTwoScientific,
156 as Str,
157 3 ▶ where{ return $_ =~ /^\-?[0-9]+\.\d{2}E-?\d{2,50}/i };#print "--$_\n";
Subroutine __ANON__: called CC=1 SCAR=0.0
158  
159 coerce SpecialTwoScientific,
160 from Str,
161 2 ▶ via{
Subroutine __ANON__: called CC=1 SCAR=0.0
162 2 my $string = $_;
163 2 $string =~ /([\-\d\.]+)[Ee](-)?(\d+)/i;#
164 #~ print "$1\n";
165 #~ print "$2\n";
166 #~ print "$3\n";
167 2 my $return = sprintf '%.2f', $1;
168 #~ print "$return\n";
169 2 $return .= 'E' . sprintf '%s%02d', $2, $3;
170 #~ print "$return\n";
171 2 return $return;
172 44 };
173  
174 declare SpecialThreeScientific,
175 as Str,
176 5 ▶ where{ return $_ =~ /^\-?[0-9]+\.\d{3}E-?\d{2,50}/i };#print "--$_\n";
Subroutine __ANON__: called CC=1 SCAR=0.0
177  
178 coerce SpecialThreeScientific,
179 from Str,
180 3 ▶ via{
Subroutine __ANON__: called CC=1 SCAR=0.0
181 3 my $string = $_;
182 3 $string =~ /([\-\d\.]+)[Ee](-)?(\d+)/i;#
183 #~ print "$1\n";
184 #~ print "$2\n";
185 #~ print "$3\n";
186 3 my $return = sprintf '%.3f', $1;
187 #~ print "$return\n";
188 3 $return .= 'E' . sprintf '%s%02d', $2, $3;
189 #~ print "$return\n";
190 3 return $return;
191 44 };
192  
193 declare SpecialFourScientific,
194 as Str,
195 3 ▶ where{ return $_ =~ /^\-?[0-9]+\.\d{4}E-?\d{2,50}/i };#print "--$_\n";
Subroutine __ANON__: called CC=1 SCAR=0.0
196  
197 coerce SpecialFourScientific,
198 from Str,
199 2 ▶ via{
Subroutine __ANON__: called CC=1 SCAR=0.0
200 2 my $string = $_;
201 2 $string =~ /([\-\d\.]+)[Ee](-)?(\d+)/i;#
202 #~ print "$1\n";
203 #~ print "$2\n";
204 #~ print "$3\n";
205 2 my $return = sprintf '%.4f', $1;
206 #~ print "$return\n";
207 2 $return .= 'E' . sprintf '%s%02d', $2, $3;
208 #~ print "$return\n";
209 2 return $return;
210 44 };
211  
212 declare SpecialFiveScientific,
213 as Str,
214 5 ▶ where{ return $_ =~ /^\-?[0-9]+\.\d{5}E-?\d{2,50}/i };#print "--$_\n";
Subroutine __ANON__: called CC=1 SCAR=0.0
215  
216 coerce SpecialFiveScientific,
217 from Str,
218 3 ▶ via{
Subroutine __ANON__: called CC=1 SCAR=0.0
219 3 my $string = $_;
220 3 $string =~ /([\-\d\.]+)[Ee](-)?(\d+)/i;#
221 #~ print "$1\n";
222 #~ print "$2\n";
223 #~ print "$3\n";
224 3 my $return = sprintf '%.5f', $1;
225 #~ print "$return\n";
226 3 $return .= 'E' . sprintf '%s%02d', $2, $3;
227 #~ print "$return\n";
228 3 return $return;
229 44 };
230  
231 declare SpecialDecimal,
232 as Str,
233 13 ▶ where{ return $_ =~ /\.\d{1,9}$/i };#print "--$_\n";
Subroutine __ANON__: called CC=1 SCAR=0.0
234  
235 coerce SpecialDecimal,
236 from Str,
237 7 ▶ via{
Subroutine __ANON__: called CC=1 SCAR=0.0
238 7 my $string = $_;
239 7 my $return = sprintf '%.9f', $string;
240 #~ print "$return\n";
241 7 $return =~ /(.*[1-9])(0*)$/;
242 7 my $significant_decimal = $1;
243 #~ print "$significant_decimal\n";
244 7 return $significant_decimal;
245 44 };
246  
247 #~ declare PositiveNum,
248 #~ as Num,
249 #~ where{ $_ > 0 };
250  
251 #~ declare NegativeNum,
252 #~ as Num,
253 #~ where{ $_ < 0 };
254  
255 #~ declare ZeroOrUndef,
256 #~ as Maybe[Num],
257 #~ where{ !$_ };
258  
259 #~ declare NotNegativeNum,
260 #~ as Num,
261 #~ where{ $_ > -1 };
262  
263 #########1 Excel Defined Converions 4#########5#########6#########7#########8#########9
264  
265 #~ declare_coercion Excel_number_0,
266 #~ to_type Any, from Maybe[Any],
267 #~ via{ $_ };
268  
269 #########1 Public Attributes 3#########4#########5#########6#########7#########8#########9
270  
271  
272  
273 #########1 Private Methods 3#########4#########5#########6#########7#########8#########9
274  
275  
276 #########1 Phinish 3#########4#########5#########6#########7#########8#########9
277  
278 44 __PACKAGE__->meta->make_immutable;
279 44 1;
280  
281 #########1 Documentation 3#########4#########5#########6#########7#########8#########9
282 __END__
« lib/Spreadsheet/Reader/ExcelXML/Row.pm ↑ Summary lib/Spreadsheet/Reader/ExcelXML/XMLReader/NamedSharedStrings.pm »