| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojo::CSV; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
934
|
use Carp qw/croak/; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
80
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use Mojo::Collection qw/c/; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
43
|
|
|
5
|
1
|
|
|
1
|
|
530
|
use Text::CSV; |
|
|
1
|
|
|
|
|
8569
|
|
|
|
1
|
|
|
|
|
45
|
|
|
6
|
1
|
|
|
1
|
|
8
|
use Scalar::Util qw/reftype/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
46
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
425
|
use Moo; |
|
|
1
|
|
|
|
|
7785
|
|
|
|
1
|
|
|
|
|
5
|
|
|
9
|
1
|
|
|
1
|
|
1442
|
use MooX::ChainedAttributes; |
|
|
1
|
|
|
|
|
8061
|
|
|
|
1
|
|
|
|
|
6
|
|
|
10
|
1
|
|
|
1
|
|
14393
|
use strictures 2; |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
45
|
|
|
11
|
1
|
|
|
1
|
|
563
|
use namespace::clean; |
|
|
1
|
|
|
|
|
8991
|
|
|
|
1
|
|
|
|
|
6
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.001003'; # VERSION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has in => ( |
|
16
|
|
|
|
|
|
|
is => 'rw', |
|
17
|
|
|
|
|
|
|
chained => 1, |
|
18
|
|
|
|
|
|
|
coerce => sub { __get_fh( $_[0], '<' ); } |
|
19
|
|
|
|
|
|
|
); |
|
20
|
|
|
|
|
|
|
has out => ( |
|
21
|
|
|
|
|
|
|
is => 'rw', |
|
22
|
|
|
|
|
|
|
chained => 1, |
|
23
|
|
|
|
|
|
|
coerce => sub { __get_fh( $_[0], '>' ); } |
|
24
|
|
|
|
|
|
|
); |
|
25
|
|
|
|
|
|
|
has _obj => ( |
|
26
|
|
|
|
|
|
|
is => 'ro', |
|
27
|
|
|
|
|
|
|
default => sub { Text::CSV->new({ binary => 1 }) }, |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub __get_fh { |
|
31
|
11
|
|
|
11
|
|
27
|
my ( $what, $how ) = @_;; |
|
32
|
|
|
|
|
|
|
|
|
33
|
11
|
|
|
|
|
18
|
my $fh; |
|
34
|
11
|
100
|
|
|
|
49
|
if ( ref $what eq 'Mojo::Asset::File' ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
5
|
$fh = $what->handle; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
elsif ( ref $what eq 'Mojo::Asset::Memory' ) { |
|
38
|
1
|
50
|
|
1
|
|
47
|
open $fh, $how, \ $what->slurp or die $!; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
19
|
|
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
elsif ( ref $what ) { |
|
41
|
1
|
|
|
|
|
2
|
$fh = $what; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
elsif ( defined $what ) { |
|
44
|
6
|
50
|
|
|
|
300
|
open $fh, $how, $what or croak "Failed to open CSV file ($what): $!"; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
else { |
|
47
|
0
|
|
|
|
|
0
|
croak 'Could not figure out how to access resource'; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
11
|
|
|
|
|
1123
|
return $fh; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub flush { |
|
54
|
4
|
|
|
4
|
1
|
11
|
my $self = shift; |
|
55
|
4
|
|
|
|
|
63
|
close $self->out; |
|
56
|
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
147
|
$self; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub row { |
|
61
|
64
|
|
|
64
|
1
|
5490
|
my $self = shift; |
|
62
|
64
|
100
|
|
|
|
930
|
my $in = $self->in or croak 'You must specify what to read from'; |
|
63
|
63
|
100
|
|
|
|
1361
|
my $row = $self->_obj->getline( $in ) or return; |
|
64
|
56
|
|
|
|
|
1493
|
return $row; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub slurp { |
|
68
|
6
|
|
|
6
|
1
|
479
|
my $self = shift; |
|
69
|
6
|
50
|
|
|
|
95
|
@_ and $self->in( shift ); |
|
70
|
|
|
|
|
|
|
|
|
71
|
6
|
|
|
|
|
46
|
my @rows; |
|
72
|
6
|
|
|
|
|
15
|
while ( my $r = $self->row ) { |
|
73
|
48
|
|
|
|
|
111
|
push @rows, $r; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
6
|
|
|
|
|
162
|
return c @rows; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub slurp_body { |
|
80
|
2
|
|
|
2
|
1
|
225
|
my $self = shift; |
|
81
|
2
|
|
|
|
|
6
|
my $r = $self->slurp( @_ ); |
|
82
|
2
|
|
|
|
|
29
|
return $r->slice( 1 .. $r->size-1 ); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub spurt { |
|
86
|
2
|
|
|
2
|
1
|
26
|
my $self = shift; |
|
87
|
2
|
|
|
|
|
5
|
my $what = shift; |
|
88
|
2
|
50
|
|
|
|
6
|
@_ and $self->out( shift ); |
|
89
|
2
|
|
|
|
|
9
|
$self->trickle( $_ ) for @$what; |
|
90
|
2
|
|
|
|
|
7
|
$self->flush; |
|
91
|
|
|
|
|
|
|
|
|
92
|
2
|
|
|
|
|
7
|
$self; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub text { |
|
96
|
9
|
|
|
9
|
1
|
4183
|
my $self = shift; |
|
97
|
9
|
50
|
|
|
|
24
|
my $what = shift or return ''; |
|
98
|
|
|
|
|
|
|
|
|
99
|
9
|
|
|
|
|
17
|
my @out; |
|
100
|
9
|
|
|
|
|
22
|
my $obj = $self->_obj; |
|
101
|
9
|
100
|
33
|
|
|
90
|
if ( reftype $what |
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
102
|
|
|
|
|
|
|
and reftype $what eq 'ARRAY' |
|
103
|
|
|
|
|
|
|
and reftype $what->[0] |
|
104
|
|
|
|
|
|
|
and reftype $what->[0] eq 'ARRAY' |
|
105
|
|
|
|
|
|
|
) { |
|
106
|
1
|
|
|
|
|
4
|
for my $row ( @$what ) { |
|
107
|
8
|
50
|
|
|
|
57
|
$obj->combine( @$row ) or next; |
|
108
|
8
|
|
|
|
|
109
|
push @out, $obj->string; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
else { |
|
112
|
8
|
50
|
|
|
|
30
|
$obj->combine( @$what ) and push @out, $obj->string; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
9
|
|
|
|
|
211
|
return join "\n", @out; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub trickle { |
|
119
|
19
|
|
|
19
|
1
|
591
|
my $self = shift; |
|
120
|
19
|
50
|
|
|
|
46
|
my $what = shift or return $self; |
|
121
|
19
|
100
|
|
|
|
268
|
my $out = $self->out or croak 'You must specify where to write'; |
|
122
|
18
|
|
|
|
|
121
|
my $obj = $self->_obj; |
|
123
|
18
|
50
|
|
|
|
52
|
$obj->combine( @$what ) or return $self; |
|
124
|
18
|
|
|
|
|
305
|
print $out $obj->string . "\n"; |
|
125
|
|
|
|
|
|
|
|
|
126
|
18
|
|
|
|
|
140
|
$self; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
q| |
|
130
|
|
|
|
|
|
|
Computers are like air conditioners. |
|
131
|
|
|
|
|
|
|
They work fine until you start opening windows. |
|
132
|
|
|
|
|
|
|
|; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |