line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package datasource; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
767
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
703
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
1
|
|
|
1
|
0
|
2699
|
my $class = shift; |
9
|
1
|
|
|
|
|
5
|
my $self = { |
10
|
|
|
|
|
|
|
'source' => [], |
11
|
|
|
|
|
|
|
}; |
12
|
1
|
|
|
|
|
2
|
bless $self, $class; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
4
|
return $self->init( @_ ); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub init { |
18
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
7
|
while () { |
21
|
34
|
|
|
|
|
33
|
chomp; |
22
|
34
|
|
|
|
|
99
|
my ($location, $zipcode, $name, $amount ) = split(/\|/, $_); |
23
|
|
|
|
|
|
|
|
24
|
34
|
|
|
|
|
72
|
my $item = datasource::item->new( |
25
|
|
|
|
|
|
|
location => $location, |
26
|
|
|
|
|
|
|
zipcode => $zipcode, |
27
|
|
|
|
|
|
|
name => $name, |
28
|
|
|
|
|
|
|
amount => $amount |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
34
|
|
|
|
|
35
|
push(@{ $self->{source} }, $item ); |
|
34
|
|
|
|
|
125
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
213
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub next { |
38
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
0
|
return shift @{ $self->{source} }; |
|
0
|
|
|
|
|
0
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub dump_as_csv { |
44
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
45
|
0
|
|
|
|
|
0
|
my $file = shift; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
0
|
open(CSV,"> $file") || die "could not open ${file} for writing - $!"; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
print CSV '"location","zipcode","name","amount"',"\n"; |
50
|
0
|
|
|
|
|
0
|
while (my $item = $self->next()) { |
51
|
0
|
|
|
|
|
0
|
print CSV sprintf('"%s","%u","%s","%.2f"', |
52
|
|
|
|
|
|
|
$item->get('location'), |
53
|
|
|
|
|
|
|
$item->get('zipcode'), |
54
|
|
|
|
|
|
|
$item->get('name'), |
55
|
|
|
|
|
|
|
$item->get('amount') ), "\n"; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
0
|
close(CSV); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
package datasource::item; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
65
|
34
|
|
|
34
|
|
33
|
my $class = shift; |
66
|
34
|
|
|
|
|
97
|
my $self = { @_ }; |
67
|
|
|
|
|
|
|
|
68
|
34
|
|
|
|
|
202
|
return bless $self,$class; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get { |
72
|
0
|
|
|
0
|
|
|
my $self = shift; |
73
|
0
|
|
|
|
|
|
my $field = shift; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return $self->{$field}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub getall { |
79
|
0
|
|
|
0
|
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
my %values = ( %{ $self} ); |
|
0
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
return wantarray ? %values : \%values; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
package datasource; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__DATA__ |