line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::CSV::Easy; |
2
|
2
|
|
|
2
|
|
79458
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
85
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
82
|
|
4
|
2
|
|
|
2
|
|
64
|
use 5.010; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
85
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
11
|
use B qw(svref_2object); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
152
|
|
7
|
2
|
|
|
2
|
|
10
|
use Exporter qw(import); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
157
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Text::CSV::Easy - Easy CSV parsing and building |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.53 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.53'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @EXPORT_OK = qw(csv_build csv_parse); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# used to ensure XS and PP stay in sync. |
24
|
|
|
|
|
|
|
our $TCE_VERSION; |
25
|
2
|
|
|
2
|
|
186
|
BEGIN { $TCE_VERSION = 2 } |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use Text::CSV::Easy qw( csv_build csv_parse ); |
30
|
|
|
|
|
|
|
$csv = csv_build(@fields); |
31
|
|
|
|
|
|
|
@fields = csv_parse($csv); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Text::CSV::Easy is a simple module for parsing and building CSV strings. This module itself is |
36
|
|
|
|
|
|
|
a lightweight wrapper around L or L. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This module conforms to RFC 4180 (L) for both parsing and building of CSV lines. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=over 4 |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item 1. Use commas to separate fields. Spaces will be considered part of the field. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
abc,def, ghi => ( 'abc', 'def', ' ghi' ) |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item 2. You may enclose fields in quotes. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
"abc","def" => ( 'abc', 'def' ) |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item 3. If your field contains a line break, a comma, or a quote, you need to enclose it in quotes. A quote should be escaped with another quote. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
"a,b","a\nb","a""b" => ( 'a,b', "a\nb", 'a"b' ) |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item 4. A trailing newline is acceptable (both LF and CRLF). |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
abc,def\n => ( 'abc', 'def' ) |
57
|
|
|
|
|
|
|
abc,def\r\n => ( 'abc', 'def' ) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=back |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
When building a string using csv_build, all non-numeric strings will always be enclosed in quotes. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $MODULE; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
BEGIN { |
68
|
2
|
|
|
2
|
|
4
|
my $xs_loaded = eval { require Text::CSV::Easy_XS; 1 }; |
|
2
|
|
|
|
|
869
|
|
|
0
|
|
|
|
|
0
|
|
69
|
2
|
50
|
33
|
|
|
19
|
if ( $xs_loaded && $Text::CSV::Easy_XS::TCE_VERSION == $TCE_VERSION ) { |
70
|
0
|
|
|
|
|
0
|
$MODULE = 'Text::CSV::Easy_XS'; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
2
|
|
|
|
|
4
|
$MODULE = 'Text::CSV::Easy_PP'; |
74
|
2
|
|
|
|
|
1046
|
require Text::CSV::Easy_PP; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
2
|
|
|
2
|
|
10
|
no strict 'refs'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
284
|
|
78
|
2
|
|
|
|
|
4
|
for ( keys %{ $MODULE . '::' } ) { |
|
2
|
|
|
|
|
14
|
|
79
|
|
|
|
|
|
|
|
80
|
16
|
100
|
|
|
|
16
|
if ( defined &{"${MODULE}::$_"} ) { |
|
16
|
|
|
|
|
52
|
|
81
|
12
|
|
|
|
|
13
|
my $ref = \&{"${MODULE}::$_"}; |
|
12
|
|
|
|
|
27
|
|
82
|
12
|
|
|
|
|
44
|
my $obj = svref_2object($ref); |
83
|
12
|
100
|
66
|
|
|
285
|
next unless $obj->isa('B::CV') && $obj->GV->STASH->NAME eq $MODULE; |
84
|
4
|
|
|
|
|
20
|
*$_ = $ref; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SUBROUTINES |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 csv_build( List @fields ) : Str |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Takes a list of fields and will generate a csv string. This subroutine will raise an exception if any errors occur. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 csv_parse( Str $string ) : List[Str] |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Parses a CSV string. Returns a list of fields it found. This subroutine will raise an exception if a string could not be properly parsed. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 module( ) : Str |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Returns the underlying module used for CSV processing. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
1
|
|
|
1
|
1
|
15
|
sub module { return $MODULE } |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |