| 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"
MC/DC0%0/1
$args{"format"} // "auto"
$args{"format"}
Truth table50%1/2
A
A= $args{"format"}
| |||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | my $filename = $args{'file'} // $args{'filename'}; | ||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{"file"} // $args{"filename"}
MC/DC0%0/2
$args{"file"} // $args{"filename"}
$args{"file"}
$args{"filename"}
Truth table33%1/3
A // B
A= $args{"file"}B= $args{"filename"}
| |||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | if (lc $format eq 'auto') | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | $format = ($filename =~ /\.([^\.]+)$/) ? lc($1) : 'auto'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 50 | 1 | return $implementation->new(%args); | |||||||||||||||||||||||||||||||||||
| 51 | }; | ||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | if ($self and !$@) | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$self and not $@
MC/DC0%0/2
$self and not $@
$self
not $@
Truth table33%1/3
A and not(B)
A= $selfB= not $@
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||
| 92 | 3 | my $fh = $self->{'_FH'}; | |||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||
| 94 | 3 | ▶ | if(!$fh) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||||||
| 96 | 1 | ▶ | my $filename = $self->{'_FILENAME'} or return; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 97 | 1 | $fh = IO::File->new; | |||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | $fh->open($filename,"w") | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||
| 116 | 3 | my @cells; | |||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||
| 118 | 3 | foreach my $item (@_) | |||||||||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||||||||||
| 120 | 6 | ▶ | if (ref $item eq 'HASH') | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if (ref $item->{content} eq 'ARRAY') | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||