line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::CSV; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1660
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
164
|
|
4
|
1
|
|
|
1
|
|
1143
|
use Mojo::Collection qw/c/; |
|
1
|
|
|
|
|
5323
|
|
|
1
|
|
|
|
|
60
|
|
5
|
1
|
|
|
1
|
|
994
|
use Text::CSV; |
|
1
|
|
|
|
|
15287
|
|
|
1
|
|
|
|
|
8
|
|
6
|
1
|
|
|
1
|
|
53
|
use Scalar::Util qw/reftype/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
134
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5241
|
use Moo; |
|
1
|
|
|
|
|
16459
|
|
|
1
|
|
|
|
|
8
|
|
9
|
1
|
|
|
1
|
|
2556
|
use MooX::ChainedAttributes; |
|
1
|
|
|
|
|
5400
|
|
|
1
|
|
|
|
|
8
|
|
10
|
1
|
|
|
1
|
|
2285
|
use strictures 2; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
51
|
|
11
|
1
|
|
|
1
|
|
978
|
use namespace::clean; |
|
1
|
|
|
|
|
13933
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.001002'; # 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
|
|
23
|
my ( $what, $how ) = @_;; |
32
|
|
|
|
|
|
|
|
33
|
11
|
|
|
|
|
13
|
my $fh; |
34
|
11
|
100
|
|
|
|
57
|
if ( ref $what eq 'Mojo::Asset::File' ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
35
|
1
|
|
|
|
|
6
|
$fh = $what->handle; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif ( ref $what eq 'Mojo::Asset::Memory' ) { |
38
|
1
|
50
|
|
1
|
|
53
|
open $fh, $how, \ $what->slurp or die $!; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
25
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
elsif ( ref $what ) { |
41
|
1
|
|
|
|
|
3
|
$fh = $what; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
elsif ( defined $what ) { |
44
|
6
|
50
|
|
|
|
438
|
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
|
|
|
|
|
1947
|
return $fh; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub flush { |
54
|
4
|
|
|
4
|
1
|
11
|
my $self = shift; |
55
|
4
|
|
|
|
|
97
|
close $self->out; |
56
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
353
|
$self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub row { |
61
|
64
|
|
|
64
|
1
|
4906
|
my $self = shift; |
62
|
64
|
100
|
|
|
|
1574
|
my $in = $self->in or croak 'You must specify what to read from'; |
63
|
1
|
100
|
|
1
|
|
7
|
my $row = $self->_obj->getline( $in ) or return; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
|
63
|
|
|
|
|
4895
|
|
64
|
56
|
|
|
|
|
2033
|
return $row; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub slurp { |
68
|
6
|
|
|
6
|
1
|
541
|
my $self = shift; |
69
|
6
|
50
|
|
|
|
179
|
@_ and $self->in( shift ); |
70
|
|
|
|
|
|
|
|
71
|
6
|
|
|
|
|
68
|
my @rows; |
72
|
6
|
|
|
|
|
18
|
while ( my $r = $self->row ) { |
73
|
48
|
|
|
|
|
136
|
push @rows, $r; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
6
|
|
|
|
|
229
|
return c @rows; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub slurp_body { |
80
|
2
|
|
|
2
|
1
|
258
|
my $self = shift; |
81
|
2
|
|
|
|
|
6
|
my $r = $self->slurp( @_ ); |
82
|
2
|
|
|
|
|
28
|
return $r->slice( 1 .. $r->size-1 ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub spurt { |
86
|
2
|
|
|
2
|
1
|
25
|
my $self = shift; |
87
|
2
|
|
|
|
|
4
|
my $what = shift; |
88
|
2
|
50
|
|
|
|
7
|
@_ and $self->out( shift ); |
89
|
2
|
|
|
|
|
9
|
$self->trickle( $_ ) for @$what; |
90
|
2
|
|
|
|
|
8
|
$self->flush; |
91
|
|
|
|
|
|
|
|
92
|
2
|
|
|
|
|
6
|
$self; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub text { |
96
|
9
|
|
|
9
|
1
|
2867
|
my $self = shift; |
97
|
9
|
50
|
|
|
|
28
|
my $what = shift or return ''; |
98
|
|
|
|
|
|
|
|
99
|
9
|
|
|
|
|
12
|
my @out; |
100
|
9
|
|
|
|
|
18
|
my $obj = $self->_obj; |
101
|
9
|
100
|
33
|
|
|
108
|
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
|
|
|
|
|
3
|
for my $row ( @$what ) { |
107
|
8
|
50
|
|
|
|
61
|
$obj->combine( @$row ) or next; |
108
|
8
|
|
|
|
|
121
|
push @out, $obj->string; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
8
|
50
|
|
|
|
28
|
$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
|
747
|
my $self = shift; |
120
|
19
|
50
|
|
|
|
45
|
my $what = shift or return $self; |
121
|
19
|
100
|
|
|
|
458
|
my $out = $self->out or croak 'You must specify where to write'; |
122
|
18
|
|
|
|
|
1146
|
my $obj = $self->_obj; |
123
|
18
|
50
|
|
|
|
59
|
$obj->combine( @$what ) or return $self; |
124
|
18
|
|
|
|
|
413
|
print $out $obj->string . "\n"; |
125
|
|
|
|
|
|
|
|
126
|
18
|
|
|
|
|
155
|
$self; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
q| |
130
|
|
|
|
|
|
|
Computers are like air conditioners. |
131
|
|
|
|
|
|
|
They work fine until you start opening windows. |
132
|
|
|
|
|
|
|
|; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |