line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::CSV::BulkData; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20299
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
1360
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
1
|
|
|
1
|
0
|
14
|
my ($class, $output_file, $format) = @_; |
11
|
1
|
|
|
|
|
6
|
bless { |
12
|
|
|
|
|
|
|
output_file => $output_file, |
13
|
|
|
|
|
|
|
format => $format, |
14
|
|
|
|
|
|
|
residue_loop => 1, |
15
|
|
|
|
|
|
|
}, $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub set_residue_loop_off { |
19
|
0
|
|
|
0
|
0
|
0
|
my ($self, $output_file) = @_; |
20
|
0
|
|
|
|
|
0
|
$self->{residue_loop} = 0; |
21
|
0
|
|
|
|
|
0
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub set_output_file { |
25
|
0
|
|
|
0
|
0
|
0
|
my ($self, $output_file) = @_; |
26
|
0
|
|
|
|
|
0
|
$self->{output_file} = $output_file; |
27
|
0
|
|
|
|
|
0
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub set_format { |
31
|
2
|
|
|
2
|
0
|
3
|
my ($self, $format) = @_; |
32
|
2
|
|
|
|
|
4
|
$self->{format} = $format; |
33
|
2
|
|
|
|
|
7
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub set_pattern { |
37
|
3
|
|
|
3
|
0
|
4
|
my $self = shift; |
38
|
3
|
|
|
|
|
7
|
$self->{pattern} = shift; |
39
|
3
|
|
|
|
|
10
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub set_start { |
43
|
3
|
|
|
3
|
0
|
6
|
my ($self, $start) = @_; |
44
|
3
|
|
|
|
|
5
|
$self->{start} = $start; |
45
|
3
|
|
|
|
|
10
|
return $self; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub set_end { |
49
|
3
|
|
|
3
|
0
|
7
|
my ($self, $end) = @_; |
50
|
3
|
|
|
|
|
5
|
$self->{end} = $end; |
51
|
3
|
|
|
|
|
13
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub initialize { |
55
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
56
|
1
|
|
|
|
|
1
|
my $output_file = $self->{output_file}; |
57
|
1
|
50
|
50
|
|
|
123
|
unlink $output_file or croak $! if -f $output_file; |
58
|
1
|
|
|
|
|
5
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub make { |
62
|
3
|
|
|
3
|
0
|
6
|
my $self = shift; |
63
|
3
|
|
|
|
|
14
|
my ($output_file, $start, $end, $format, $pattern ) = |
64
|
|
|
|
|
|
|
( $self->{output_file}, $self->{start}, $self->{end}, $self->{format}, $self->{pattern} ); |
65
|
3
|
|
|
|
|
3
|
my $debug_ary_ref; |
66
|
|
|
|
|
|
|
|
67
|
3
|
50
|
|
|
|
221
|
open FH, ">> $output_file" or croak $!; |
68
|
3
|
|
|
|
|
13
|
for (my $i = $start; $i <= $end; $i++){ |
69
|
10
|
|
|
|
|
17
|
my @input = (); |
70
|
10
|
|
|
|
|
58
|
for (my $j = 0; $j < ($format =~ s/%/%/g); $j++) { |
71
|
56
|
|
|
|
|
74
|
my $pattern = $$pattern[$j]; |
72
|
56
|
100
|
|
|
|
165
|
if ( ! defined $pattern ) { |
|
|
100
|
|
|
|
|
|
73
|
8
|
|
|
|
|
10
|
push @input, $i; |
74
|
8
|
|
|
|
|
43
|
next; |
75
|
|
|
|
|
|
|
} elsif ( $pattern !~ m/^[%\/\*\+-]/ ) { |
76
|
8
|
|
|
|
|
10
|
push @input, $pattern; |
77
|
8
|
|
|
|
|
41
|
next; |
78
|
|
|
|
|
|
|
} |
79
|
40
|
|
|
|
|
1064
|
push @input, $self->_calculate($pattern, $i, 0); |
80
|
|
|
|
|
|
|
} |
81
|
10
|
50
|
|
|
|
85
|
$self->{debug} |
82
|
|
|
|
|
|
|
? push @$debug_ary_ref, sprintf $format, @input |
83
|
|
|
|
|
|
|
: printf FH $format, @input; |
84
|
|
|
|
|
|
|
} |
85
|
3
|
|
|
|
|
45
|
close FH; |
86
|
|
|
|
|
|
|
|
87
|
3
|
50
|
|
|
|
21
|
$self->{debug} |
88
|
|
|
|
|
|
|
? return $debug_ary_ref |
89
|
|
|
|
|
|
|
: return $self; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _calculate { |
93
|
132
|
|
|
132
|
|
349
|
my ($self, $pattern, $i, $flag) = @_; |
94
|
132
|
100
|
100
|
|
|
502
|
if ( ! $flag && $self->_is_recursive_start($pattern) ) { |
95
|
26
|
|
|
|
|
51
|
$pattern =~ m{^(\d+)[^0-9]}; |
96
|
26
|
|
|
|
|
49
|
$self->{pattern} = $pattern; |
97
|
26
|
|
|
|
|
45
|
$self->{before} = $1; |
98
|
26
|
|
|
|
|
232
|
$pattern =~ s{^\d+([^0-9])}{$1}; |
99
|
26
|
|
|
|
|
64
|
return $self->_calculate($pattern, $i, 1); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
106
|
100
|
|
|
|
1064
|
if ( $pattern =~ m{\*(\d+)} ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
103
|
18
|
100
|
|
|
|
33
|
if ( $flag eq 1) { |
104
|
5
|
|
|
|
|
12
|
my $res = $self->{before} * $1; |
105
|
5
|
|
|
|
|
11
|
$res = $self->_recursive_calc($res); |
106
|
5
|
|
|
|
|
179
|
$pattern = $self->_return_substituted('^\d+\*\d+', $res); |
107
|
|
|
|
|
|
|
} else { |
108
|
13
|
|
|
|
|
29
|
my $res = $i * $1; |
109
|
13
|
|
|
|
|
38
|
$pattern =~ s{\*\d+}{$res}; |
110
|
|
|
|
|
|
|
} |
111
|
18
|
|
|
|
|
46
|
$self->_calculate($pattern, $i, 0); |
112
|
|
|
|
|
|
|
} elsif ( $pattern =~ m{/(\d+)} ) { |
113
|
6
|
100
|
|
|
|
12
|
if ( $flag eq 1) { |
114
|
3
|
|
|
|
|
8
|
my $res = int($self->{before} / $1); |
115
|
3
|
|
|
|
|
7
|
$res = $self->_recursive_calc($res); |
116
|
3
|
|
|
|
|
7
|
$pattern = $self->_return_substituted('^\d+/\d+', $res); |
117
|
|
|
|
|
|
|
} else { |
118
|
3
|
|
|
|
|
9
|
my $res = int($i / $1); |
119
|
3
|
|
|
|
|
11
|
$pattern =~ s{/\d+}{$res}; |
120
|
|
|
|
|
|
|
} |
121
|
6
|
|
|
|
|
18
|
$self->_calculate($pattern, $i, 0); |
122
|
|
|
|
|
|
|
} elsif ( $pattern =~ m{%(\d+)} ) { |
123
|
19
|
50
|
|
|
|
50
|
$self->{residue_loop} = $1 if $self->{residue_loop}; |
124
|
19
|
50
|
|
|
|
35
|
if ( $flag eq 1) { |
125
|
0
|
|
|
|
|
0
|
my $res = $self->{before} % $1; |
126
|
0
|
|
|
|
|
0
|
$res = $self->_recursive_calc($res); |
127
|
0
|
|
|
|
|
0
|
$pattern = $self->_return_substituted('^\d+%\d+', $res); |
128
|
|
|
|
|
|
|
} else { |
129
|
19
|
|
|
|
|
34
|
my $res = $i % $1; |
130
|
19
|
|
|
|
|
612
|
$pattern =~ s{%\d+}{$res}; |
131
|
|
|
|
|
|
|
} |
132
|
19
|
|
|
|
|
42
|
$self->_calculate($pattern, $i, 0); |
133
|
|
|
|
|
|
|
} elsif ( $pattern =~ m{\+(\d+)} ) { |
134
|
5
|
50
|
|
|
|
12
|
if ( $flag eq 1) { |
135
|
5
|
|
|
|
|
10
|
my $res = $self->{before} + $1; |
136
|
5
|
|
|
|
|
10
|
$res = $self->_recursive_calc($res); |
137
|
5
|
|
|
|
|
21
|
$pattern = $self->_return_substituted('^\d+\+\d+', $res); |
138
|
|
|
|
|
|
|
} else { |
139
|
0
|
|
|
|
|
0
|
my $res = $i + $1; |
140
|
0
|
|
|
|
|
0
|
$pattern =~ s{\+\d+}{$res}; |
141
|
|
|
|
|
|
|
} |
142
|
5
|
|
|
|
|
12
|
$self->_calculate($pattern, $i, 0); |
143
|
|
|
|
|
|
|
} elsif ( $pattern =~ m{-(\d+)} ) { |
144
|
18
|
100
|
|
|
|
217
|
if ( $flag eq 1) { |
145
|
13
|
|
|
|
|
29
|
my $res = $self->{before} - $1; |
146
|
13
|
|
|
|
|
22
|
$res = $self->_recursive_calc($res); |
147
|
13
|
|
|
|
|
25
|
$pattern = $self->_return_substituted('^\d+-\d+', $res); |
148
|
|
|
|
|
|
|
} else { |
149
|
5
|
|
|
|
|
13
|
my $res = $i - $1; |
150
|
5
|
|
|
|
|
16
|
$pattern =~ s{-\d+}{$res}; |
151
|
|
|
|
|
|
|
} |
152
|
18
|
|
|
|
|
226
|
$self->_calculate($pattern, $i, 0); |
153
|
|
|
|
|
|
|
} else { |
154
|
40
|
|
|
|
|
251
|
delete $self->{pattern}, $self->{before}; |
155
|
40
|
|
|
|
|
48
|
$self->{residue_loop} = 1; |
156
|
40
|
|
|
|
|
689
|
return $pattern; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub _recursive_calc { |
161
|
26
|
|
|
26
|
|
31
|
my ($self, $res) = @_; |
162
|
26
|
100
|
66
|
|
|
479
|
if ( defined $self->{residue_loop} |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
163
|
|
|
|
|
|
|
&& $self->{residue_loop} > 1 |
164
|
|
|
|
|
|
|
&& ($res < 0 || $res > $self->{residue_loop}) |
165
|
|
|
|
|
|
|
) { |
166
|
5
|
|
|
|
|
8
|
$res += $self->{residue_loop}; |
167
|
|
|
|
|
|
|
} |
168
|
26
|
|
|
|
|
386
|
return $res; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub _return_substituted { |
172
|
26
|
|
|
26
|
|
32
|
my ($self, $regexp, $res) = @_; |
173
|
26
|
|
|
|
|
928
|
$self->{pattern} =~ s{$regexp}{$res}; |
174
|
26
|
|
|
|
|
245
|
return $self->{pattern}; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub _is_recursive_start { |
178
|
106
|
|
|
106
|
|
104
|
my $self = shift; |
179
|
106
|
|
|
|
|
133
|
my $pattern = shift; |
180
|
106
|
100
|
100
|
|
|
2032
|
( $pattern =~ /^\d+/ && $pattern !~ /^\d+$/ ) ? return 1 : return 0; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub _set_debug { |
184
|
1
|
|
|
1
|
|
312
|
my $self = shift; |
185
|
1
|
|
|
|
|
4
|
$self->{debug} = 1; |
186
|
1
|
|
|
|
|
2
|
return $self; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
1; |
190
|
|
|
|
|
|
|
__END__ |