blib/lib/Text/CSV/BulkData.pm

filter: Statementstmt 90.1% 101 / 112 Branchbran 84.0% 37 / 44 Conditioncond 73.6% 14 / 19 MC/DCmcdc 60.0% 6 / 10 Subroutinesub 88.2% 15 / 17 Podpod 0.0% 0 / 9 totaltotal 81.9% 173 / 211 CC 29 SCAR 19.7
CC
29
Cov
87%
_calculate
14.2
make
8.1
_recursive_calc
5.1
CRAP 7.2
↑ Summary
1 package Text::CSV::BulkData;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = '0.06';
6  
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
10 1 my ($class, $output_file, $format) = @_;
11 1 bless {
12 output_file => $output_file,
13 format => $format,
14 residue_loop => 1,
15 }, $class;
16 }
17  
18 0 ▶sub set_residue_loop_off {
Subroutine set_residue_loop_off: not called CC=1 SCAR=6.9
Pod undocumented
19 0 my ($self, $output_file) = @_;
20 0 $self->{residue_loop} = 0;
21 0 return $self;
22 }
23  
24 0 ▶sub set_output_file {
Subroutine set_output_file: not called CC=1 SCAR=6.9
Pod undocumented
25 0 my ($self, $output_file) = @_;
26 0 $self->{output_file} = $output_file;
27 0 return $self;
28 }
29  
30 2 ▶sub set_format {
Subroutine set_format: called CC=1 SCAR=0.0
Pod undocumented
31 2 my ($self, $format) = @_;
32 2 $self->{format} = $format;
33 2 return $self;
34 }
35  
36 3 ▶sub set_pattern {
Subroutine set_pattern: called CC=1 SCAR=0.0
Pod undocumented
37 3 my $self = shift;
38 3 $self->{pattern} = shift;
39 3 return $self;
40 }
41  
42 3 ▶sub set_start {
Subroutine set_start: called CC=1 SCAR=0.0
Pod undocumented
43 3 my ($self, $start) = @_;
44 3 $self->{start} = $start;
45 3 return $self;
46 }
47  
48 3 ▶sub set_end {
Subroutine set_end: called CC=1 SCAR=0.0
Pod undocumented
49 3 my ($self, $end) = @_;
50 3 $self->{end} = $end;
51 3 return $self;
52 }
53  
54 1 ▶sub initialize {
Subroutine initialize: called CC=3 SCAR=12.7
Pod undocumented
55 1 my $self = shift;
56 1 my $output_file = $self->{output_file};
57 1 ▶ unlink $output_file or croak $! if -f $output_file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $output_file 0 1 1
Condition25%1/4
-f $output_file && (unlink($output_file) || croak($!))
!ll
10
unlink $output_file or croak($!)
l!l
00
MC/DC0%0/2
-f $output_file && (unlink($output_file) || croak($!))
-f $output_file unlink $output_file
Truth table33%1/3
A && B
A= -f $output_fileB= unlink $output_file
ABresult
0X0
100
111
58 1 return $self;
59 }
60  
61 3 ▶sub make {
Subroutine make: called CC=8 SCAR=20.9
Pod undocumented
62 3 my $self = shift;
63 my ($output_file, $start, $end, $format, $pattern ) =
64 3 ( $self->{output_file}, $self->{start}, $self->{end}, $self->{format}, $self->{pattern} );
65 3 my $debug_ary_ref;
66  
67 3 ▶ open FH, ">> $output_file" or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
open FH, ">> $output_file" or croak($!) 3 0 3
68 3 ▶ for (my $i = $start; $i <= $end; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $end) 10 3 13
69 10 my @input = ();
70 10 ▶ for (my $j = 0; $j < ($format =~ s/%/%/g); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $format =~ s/%/%/g) 56 10 66
71 56 my $pattern = $$pattern[$j];
72 56 ▶ if ( ! defined $pattern ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $pattern) { } 8 48 56
elsif (not $pattern =~ m[^[%/\*\+-]]) { } 8 40 48
73 8 push @input, $i;
74 8 next;
75 } elsif ( $pattern !~ m/^[%\/\*\+-]/ ) {
76 8 push @input, $pattern;
77 8 next;
78 }
79 40 push @input, $self->_calculate($pattern, $i, 0);
80 }
81 $self->{debug}
82 10 ▶ ? push @$debug_ary_ref, sprintf $format, @input
Branch: 1 branch
BranchTrueFalseTotal
$self->{'debug'} ? : 10 0 10
83 : printf FH $format, @input;
84 }
85 3 close FH;
86
87 $self->{debug}
88 3 ▶ ? return $debug_ary_ref
Branch: 1 branch
BranchTrueFalseTotal
$self->{'debug'} ? : 3 0 3
89 : return $self;
90 }
91  
92 132 ▶sub _calculate {
Subroutine _calculate: called CC=14 SCAR=26.6
93 132 my ($self, $pattern, $i, $flag) = @_;
94 132 ▶ if ( ! $flag && $self->_is_recursive_start($pattern) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $flag and $self->_is_recursive_start($pattern)) 26 106 132
Condition100%3/3
not $flag and $self->_is_recursive_start($pattern)
!ll&&!rl&&r
268026
MC/DC100%2/2
not $flag and $self->_is_recursive_start($pattern)
not $flag $self->_is_recursive_start($pattern)
Truth table100%3/3
not(A) and B
A= not $flagB= $self->_is_recursive_start($pattern)
ABresult
0X0
100
111
95 26 $pattern =~ m{^(\d+)[^0-9]};
96 26 $self->{pattern} = $pattern;
97 26 $self->{before} = $1;
98 26 $pattern =~ s{^\d+([^0-9])}{$1};
99 26 return $self->_calculate($pattern, $i, 1);
100 }
101  
102 106 ▶ if ( $pattern =~ m{\*(\d+)} ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($pattern =~ /\*(\d+)/) { } 18 88 106
elsif ($pattern =~ m[/(\d+)]) { } 6 82 88
elsif ($pattern =~ /%(\d+)/) { } 19 63 82
elsif ($pattern =~ /\+(\d+)/) { } 5 58 63
elsif ($pattern =~ /-(\d+)/) { } 18 40 58
103 18 ▶ if ( $flag eq 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag eq 1) { } 5 13 18
104 5 my $res = $self->{before} * $1;
105 5 $res = $self->_recursive_calc($res);
106 5 $pattern = $self->_return_substituted('^\d+\*\d+', $res);
107 } else {
108 13 my $res = $i * $1;
109 13 $pattern =~ s{\*\d+}{$res};
110 }
111 18 $self->_calculate($pattern, $i, 0);
112 } elsif ( $pattern =~ m{/(\d+)} ) {
113 6 ▶ if ( $flag eq 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag eq 1) { } 3 3 6
114 3 my $res = int($self->{before} / $1);
115 3 $res = $self->_recursive_calc($res);
116 3 $pattern = $self->_return_substituted('^\d+/\d+', $res);
117 } else {
118 3 my $res = int($i / $1);
119 3 $pattern =~ s{/\d+}{$res};
120 }
121 6 $self->_calculate($pattern, $i, 0);
122 } elsif ( $pattern =~ m{%(\d+)} ) {
123 19 ▶ $self->{residue_loop} = $1 if $self->{residue_loop};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"residue_loop"} 19 0 19
124 19 ▶ if ( $flag eq 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag eq 1) { } 0 19 19
125 0 my $res = $self->{before} % $1;
126 0 $res = $self->_recursive_calc($res);
127 0 $pattern = $self->_return_substituted('^\d+%\d+', $res);
128 } else {
129 19 my $res = $i % $1;
130 19 $pattern =~ s{%\d+}{$res};
131 }
132 19 $self->_calculate($pattern, $i, 0);
133 } elsif ( $pattern =~ m{\+(\d+)} ) {
134 5 ▶ if ( $flag eq 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag eq 1) { } 5 0 5
135 5 my $res = $self->{before} + $1;
136 5 $res = $self->_recursive_calc($res);
137 5 $pattern = $self->_return_substituted('^\d+\+\d+', $res);
138 } else {
139 0 my $res = $i + $1;
140 0 $pattern =~ s{\+\d+}{$res};
141 }
142 5 $self->_calculate($pattern, $i, 0);
143 } elsif ( $pattern =~ m{-(\d+)} ) {
144 18 ▶ if ( $flag eq 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag eq 1) { } 13 5 18
145 13 my $res = $self->{before} - $1;
146 13 $res = $self->_recursive_calc($res);
147 13 $pattern = $self->_return_substituted('^\d+-\d+', $res);
148 } else {
149 5 my $res = $i - $1;
150 5 $pattern =~ s{-\d+}{$res};
151 }
152 18 $self->_calculate($pattern, $i, 0);
153 } else {
154 40 delete $self->{pattern}, $self->{before};
155 40 $self->{residue_loop} = 1;
156 40 return $pattern;
157 }
158 }
159  
160 26 ▶sub _recursive_calc {
Subroutine _recursive_calc: called CC=5 SCAR=16.2
161 26 my ($self, $res) = @_;
162 26 ▶ if ( defined $self->{residue_loop}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"residue_loop"} and $self->{"residue_loop"} > 1 and $res < 0 || $res > $self->{"residue_loop"}) 5 21 26
Condition77%7/9
defined $self->{"residue_loop"} and $self->{"residue_loop"} > 1 and $res < 0 || $res > $self->{"residue_loop"}
!ll&&!rl&&r
1385
defined $self->{"residue_loop"} and $self->{"residue_loop"} > 1
!ll&&!rl&&r
01313
$res < 0 or $res > $self->{"residue_loop"}
l!l&&r!l&&!r
508
MC/DC50%2/4
defined $self->{"residue_loop"} and $self->{"residue_loop"} > 1 and $res < 0 || $res > $self->{"residue_loop"}
defined $self->{"residue_loop"} $self->{"residue_loop"} > 1 $res < 0 $res > $self->{"residue_loop"}
Truth table60%3/5
A and B and C or D
A= defined $self->{"residue_loop"}B= $self->{"residue_loop"} > 1C= $res < 0D= $res > $self->{"residue_loop"}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
163 && $self->{residue_loop} > 1
164 && ($res < 0 || $res > $self->{residue_loop})
165 ) {
166 5 $res += $self->{residue_loop};
167 }
168 26 return $res;
169 }
170  
171 26 ▶sub _return_substituted {
Subroutine _return_substituted: called CC=1 SCAR=0.0
172 26 my ($self, $regexp, $res) = @_;
173 26 $self->{pattern} =~ s{$regexp}{$res};
174 26 return $self->{pattern};
175 }
176  
177 106 ▶sub _is_recursive_start {
Subroutine _is_recursive_start: called CC=3 SCAR=11.0
178 106 my $self = shift;
179 106 my $pattern = shift;
180 106 ▶ ( $pattern =~ /^\d+/ && $pattern !~ /^\d+$/ ) ? return 1 : return 0;
Branch: 1 branch
BranchTrueFalseTotal
$pattern =~ /^\d+/ && !($pattern =~ /^\d+$/) ? : 26 80 106
Condition100%3/3
$pattern =~ /^\d+/ and not $pattern =~ /^\d+$/
!ll&&!rl&&r
404026
MC/DC100%2/2
$pattern =~ /^\d+/ and not $pattern =~ /^\d+$/
$pattern =~ /^\d+/ not $pattern =~ /^\d+$/
Truth table100%3/3
A and not(B)
A= $pattern =~ /^\d+/B= not $pattern =~ /^\d+$/
ABresult
0X0
100
111
181 }
182  
183 1 ▶sub _set_debug {
Subroutine _set_debug: called CC=1 SCAR=0.0
184 1 my $self = shift;
185 1 $self->{debug} = 1;
186 1 return $self;
187 }
188  
189 1 1;
190 __END__
↑ Summary