Wright.pm

filter: Statementstmt 74.0% 60 / 81 Branchbran 38.2% 13 / 34 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 68.4% 13 / 19 Podpod 100% 7 / 7 totaltotal 62.3% 96 / 154 CC 24 SCAR 24.0
CC
24
Cov
62%
new
26.8
addrow
12.0
addrows
5.5
CRAP 11.0
« Wright/XHTML.pm ↑ Summary Wright/OpenDocumentXML.pm »
1 package Spreadsheet::Wright;
2  
3 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶no warnings qw( uninitialized numeric );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 $Spreadsheet::Wright::VERSION = '0.107';
10 2 $Spreadsheet::Wright::AUTHORITY = 'cpan:TOBYINK';
11 }
12  
13 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub new
17 1 ▶{
Subroutine new: called CC=12 SCAR=32.9
Pod documented
18 1 my ($class, %args) = @_;
19
20 1 ▶ my $format = $args{'format'} // 'auto';
Condition50%1/2
$args{"format"} // "auto"
l!l
01
MC/DC0%0/1
$args{"format"} // "auto"
$args{"format"}
Truth table50%1/2
A
A= $args{"format"}
Aresult
11
00
21 1 ▶ my $filename = $args{'file'} // $args{'filename'};
Condition33%1/3
$args{"file"} // $args{"filename"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$args{"file"} // $args{"filename"}
$args{"file"} $args{"filename"}
Truth table33%1/3
A // B
A= $args{"file"}B= $args{"filename"}
ABresult
1X1
011
000
22
23 1 ▶ if (lc $format eq 'auto')
Branch: 1 branch
BranchTrueFalseTotal
if (lc $format eq "auto") 1 0 1
24 {
25 1 ▶ $format = ($filename =~ /\.([^\.]+)$/) ? lc($1) : 'auto';
Branch: 1 branch
BranchTrueFalseTotal
$filename =~ /\.([^\.]+)$/ ? : 1 0 1
26 }
27
28 my $implementation = {
29 auto => 'CSV',
30 csv => 'CSV',
31 excel => 'Excel',
32 html => 'HTML',
33 json => 'JSON',
34 ods => 'OpenDocument',
35 odsxml => 'OpenDocumentXML',
36 text => 'CSV',
37 txt => 'CSV',
38 xhtml => 'XHTML',
39 xls => 'Excel',
40 xml => 'OpenDocumentXML',
41 xlsx => 'OOXML',
42 1 }->{lc $format};
43
44 my $self = eval
45 1 {
46 1 ▶ croak "Format $format is not supported" unless $implementation;
Branch: 1 branch
BranchTrueFalseTotal
unless $implementation 0 1 1
47 1 $implementation = join '::', (__PACKAGE__, $implementation);
48 1 ▶ eval "use $implementation;";
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
50 1 return $implementation->new(%args);
51 };
52
53 1 ▶ if ($self and !$@)
Branch: 3 branches
BranchTrueFalseTotal
if ($self and not $@) { } 1 0 1
elsif ($args{'failsafe'}) { } 0 0 0
elsif ($@) { } 0 0 0
Condition33%1/3
$self and not $@
!ll&&!rl&&r
001
MC/DC0%0/2
$self and not $@
$self not $@
Truth table33%1/3
A and not(B)
A= $selfB= not $@
ABresult
0X0
100
111
54 {
55 1 return $self;
56 }
57 elsif ($args{'failsafe'})
58 {
59 0 $implementation = join '::', (__PACKAGE__, 'CSV');
60 0 eval "use $implementation;";
61 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
62 0 return $implementation->new(%args);
63 }
64 elsif ($@)
65 {
66 0 die $@;
67 }
68 else
69 {
70 0 croak "Could not instantiate spreadsheet!\n";
71 }
72 }
73  
74 sub DESTROY
75 1 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
76 1 my $self = shift;
77 1 $self->close;
78 }
79  
80 sub error
81 0 ▶{
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
82 0 my $self = shift;
83 0 return $self->{'_ERROR'};
84 }
85  
86 sub _open
87 3 ▶{
Subroutine _open: called CC=5 SCAR=16.4
88 3 my $self=shift;
89
90 3 ▶ $self->{'_CLOSED'} && croak "Can't reuse a closed spreadsheet";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_CLOSED"} and croak("Can't reuse a closed spreadsheet") 0 3 3
91
92 3 my $fh = $self->{'_FH'};
93
94 3 ▶ if(!$fh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh) 1 2 3
95 {
96 1 ▶ my $filename = $self->{'_FILENAME'} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $filename = $self->{"_FILENAME"} or return 1 0 1
97 1 $fh = IO::File->new;
98 1 ▶ $fh->open($filename,"w")
Branch: 1 branch
BranchTrueFalseTotal
$fh->open($filename, "w") or croak("Can't open file $filename for writing: $!") 1 0 1
99 or croak "Can't open file $filename for writing: $!";
100 1 $self->{'_FH'}=$fh;
101 }
102
103 3 return $self->_prepare;
104 }
105  
106 sub _prepare
107 0 ▶{
Subroutine _prepare: not called CC=1 SCAR=6.9
108 0 return $_[0];
109 }
110  
111 sub addrow
112 3 ▶{
Subroutine addrow: called CC=6 SCAR=24.8
Pod documented
113 3 my $self = shift;
114 3 ▶ $self->_open() or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_open or return 3 0 3
115
116 3 my @cells;
117
118 3 foreach my $item (@_)
119 {
120 6 ▶ if (ref $item eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item eq 'HASH') { } 0 6 6
121 {
122 0 ▶ if (ref $item->{content} eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item->{'content'} eq 'ARRAY') { } 0 0 0
123 {
124 0 foreach my $i (@{ $item->{'content'} })
125 {
126 0 my %newitem = %$item;
127 0 $newitem{'content'} = $i;
128 0 push @cells, \%newitem;
129 }
130 }
131 else
132 {
133 0 push @cells, $item;
134 }
135 }
136 else
137 {
138 6 push @cells, { content => $item };
139 }
140 }
141
142 3 return $self->_add_prepared_row(@cells);
143 }
144  
145 sub _add_prepared_row
146 0 ▶{
Subroutine _add_prepared_row: not called CC=1 SCAR=6.9
147 0 return $_[0];
148 }
149  
150 sub addrows
151 1 ▶{
Subroutine addrows: called CC=4 SCAR=17.1
Pod documented
152 1 my $self = shift;
153 1 foreach my $row (@_)
154 {
155 2 ▶ if (ref $row eq 'ARRAY')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $row eq 'ARRAY') { } 2 0 2
elsif (not ref $row) { } 0 0 0
156 {
157 2 $self->addrow(@$row);
158 }
159 elsif (!ref $row)
160 {
161 0 $self->addsheet($row);
162 }
163 else
164 {
165 0 carp "Could not add row.";
166 }
167 }
168 1 return $self;
169 }
170  
171 sub addsheet
172 0 ▶{
Subroutine addsheet: not called CC=1 SCAR=6.9
Pod documented
173 0 croak "addsheet not implemented!!\n";
174 }
175  
176 sub freeze
177 0 ▶{
Subroutine freeze: not called CC=1 SCAR=6.9
Pod documented
178 0 return $_[0];
179 }
180  
181 sub close
182 0 ▶{
Subroutine close: not called CC=1 SCAR=0.0
Pod documented
183 # noop
184 }
185  
186 2 1;
187  
188 __END__
« Wright/XHTML.pm ↑ Summary Wright/OpenDocumentXML.pm »