line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::CSV; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
36
|
|
|
36
|
|
2525432
|
use strict; |
|
36
|
|
|
|
|
395
|
|
|
36
|
|
|
|
|
1090
|
|
5
|
36
|
|
|
36
|
|
181
|
use Exporter; |
|
36
|
|
|
|
|
81
|
|
|
36
|
|
|
|
|
1369
|
|
6
|
36
|
|
|
36
|
|
208
|
use Carp (); |
|
36
|
|
|
|
|
91
|
|
|
36
|
|
|
|
|
1146
|
|
7
|
36
|
|
|
36
|
|
231
|
use vars qw( $VERSION $DEBUG @ISA @EXPORT_OK %EXPORT_TAGS ); |
|
36
|
|
|
|
|
65
|
|
|
36
|
|
|
|
|
3873
|
|
8
|
|
|
|
|
|
|
@ISA = qw( Exporter ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
BEGIN { |
11
|
36
|
|
|
36
|
|
145
|
$VERSION = '2.03'; |
12
|
36
|
|
|
|
|
16094
|
$DEBUG = 0; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# if use CSV_XS, requires version |
16
|
|
|
|
|
|
|
my $Module_XS = 'Text::CSV_XS'; |
17
|
|
|
|
|
|
|
my $Module_PP = 'Text::CSV_PP'; |
18
|
|
|
|
|
|
|
my $XS_Version = '1.51'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $Is_Dynamic = 0; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my @PublicMethods = qw/ |
23
|
|
|
|
|
|
|
version error_diag error_input |
24
|
|
|
|
|
|
|
known_attributes |
25
|
|
|
|
|
|
|
PV IV NV CSV_TYPE_PV CSV_TYPE_IV CSV_TYPE_NV |
26
|
|
|
|
|
|
|
CSV_FLAGS_IS_QUOTED CSV_FLAGS_IS_BINARY CSV_FLAGS_ERROR_IN_FIELD CSV_FLAGS_IS_MISSING |
27
|
|
|
|
|
|
|
/; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
30
|
|
|
|
|
|
|
CONSTANTS => [qw( |
31
|
|
|
|
|
|
|
CSV_FLAGS_IS_QUOTED |
32
|
|
|
|
|
|
|
CSV_FLAGS_IS_BINARY |
33
|
|
|
|
|
|
|
CSV_FLAGS_ERROR_IN_FIELD |
34
|
|
|
|
|
|
|
CSV_FLAGS_IS_MISSING |
35
|
|
|
|
|
|
|
CSV_TYPE_PV |
36
|
|
|
|
|
|
|
CSV_TYPE_IV |
37
|
|
|
|
|
|
|
CSV_TYPE_NV |
38
|
|
|
|
|
|
|
)], |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
@EXPORT_OK = (qw(csv PV IV NV), @{$EXPORT_TAGS{CONSTANTS}}); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Check the environment variable to decide worker module. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
unless ($Text::CSV::Worker) { |
47
|
|
|
|
|
|
|
$Text::CSV::DEBUG and Carp::carp("Check used worker module..."); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
if ( exists $ENV{PERL_TEXT_CSV} ) { |
50
|
|
|
|
|
|
|
if ($ENV{PERL_TEXT_CSV} eq '0' or $ENV{PERL_TEXT_CSV} eq 'Text::CSV_PP') { |
51
|
|
|
|
|
|
|
_load_pp() or Carp::croak $@; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ($ENV{PERL_TEXT_CSV} eq '1' or $ENV{PERL_TEXT_CSV} =~ /Text::CSV_XS\s*,\s*Text::CSV_PP/) { |
54
|
|
|
|
|
|
|
_load_xs() or _load_pp() or Carp::croak $@; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif ($ENV{PERL_TEXT_CSV} eq '2' or $ENV{PERL_TEXT_CSV} eq 'Text::CSV_XS') { |
57
|
|
|
|
|
|
|
_load_xs() or Carp::croak $@; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
|
|
|
|
|
|
Carp::croak "The value of environmental variable 'PERL_TEXT_CSV' is invalid."; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
|
|
|
|
|
|
_load_xs() or _load_pp() or Carp::croak $@; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub new { # normal mode |
70
|
654
|
|
|
654
|
1
|
605229
|
my $proto = shift; |
71
|
654
|
|
100
|
|
|
2970
|
my $class = ref($proto) || $proto; |
72
|
|
|
|
|
|
|
|
73
|
654
|
100
|
|
|
|
1515
|
unless ( $proto ) { # for Text::CSV_XS/PP::new(0); |
74
|
1
|
|
|
|
|
66
|
return eval qq| $Text::CSV::Worker\::new( \$proto ) |; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#if (ref $_[0] and $_[0]->{module}) { |
78
|
|
|
|
|
|
|
# Carp::croak("Can't set 'module' in non dynamic mode."); |
79
|
|
|
|
|
|
|
#} |
80
|
|
|
|
|
|
|
|
81
|
653
|
100
|
|
|
|
2718
|
if ( my $obj = $Text::CSV::Worker->new(@_) ) { |
82
|
602
|
|
|
|
|
1427
|
$obj->{_MODULE} = $Text::CSV::Worker; |
83
|
602
|
|
|
|
|
1043
|
bless $obj, $class; |
84
|
602
|
|
|
|
|
4632
|
return $obj; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
50
|
|
|
|
|
166
|
return; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub csv { |
94
|
324
|
100
|
100
|
324
|
1
|
62641
|
if (@_ && ref $_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__->backend) { |
|
|
|
66
|
|
|
|
|
95
|
15
|
|
|
|
|
48
|
splice @_, 0, 0, "csv"; |
96
|
|
|
|
|
|
|
} |
97
|
324
|
|
|
|
|
711
|
my $backend = __PACKAGE__->backend; |
98
|
36
|
|
|
36
|
|
289
|
no strict 'refs'; |
|
36
|
|
|
|
|
72
|
|
|
36
|
|
|
|
|
12718
|
|
99
|
324
|
|
|
|
|
567
|
&{"$backend\::csv"}(@_); |
|
324
|
|
|
|
|
1481
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
0
|
0
|
0
|
sub require_xs_version { $XS_Version; } |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub module { |
106
|
637
|
|
|
637
|
0
|
1151
|
my $proto = shift; |
107
|
|
|
|
|
|
|
return !ref($proto) ? $Text::CSV::Worker |
108
|
637
|
50
|
|
|
|
1985
|
: ref($proto->{_MODULE}) ? ref($proto->{_MODULE}) : $proto->{_MODULE}; |
|
|
100
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
*backend = *module; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub is_xs { |
115
|
0
|
|
|
0
|
1
|
0
|
return $_[0]->module eq $Module_XS; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub is_pp { |
120
|
2
|
|
|
2
|
1
|
1137
|
return $_[0]->module eq $Module_PP; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
0
|
0
|
0
|
sub is_dynamic { $Is_Dynamic; } |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
0
|
|
0
|
sub _load_xs { _load($Module_XS, $XS_Version) } |
127
|
|
|
|
|
|
|
|
128
|
36
|
|
|
36
|
|
97
|
sub _load_pp { _load($Module_PP) } |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _load { |
131
|
36
|
|
|
36
|
|
87
|
my ($module, $version) = @_; |
132
|
36
|
|
50
|
|
|
230
|
$version ||= ''; |
133
|
|
|
|
|
|
|
|
134
|
36
|
50
|
|
|
|
89
|
$Text::CSV::DEBUG and Carp::carp "Load $module."; |
135
|
|
|
|
|
|
|
|
136
|
36
|
|
|
36
|
|
40958
|
eval qq| use $module $version |; |
|
36
|
|
|
|
|
209
|
|
|
36
|
|
|
|
|
1607
|
|
|
36
|
|
|
|
|
2582
|
|
137
|
|
|
|
|
|
|
|
138
|
36
|
50
|
|
|
|
211
|
return if $@; |
139
|
|
|
|
|
|
|
|
140
|
36
|
|
|
|
|
421
|
push @Text::CSV::ISA, $module; |
141
|
36
|
|
|
|
|
146
|
$Text::CSV::Worker = $module; |
142
|
|
|
|
|
|
|
|
143
|
36
|
|
|
|
|
451
|
local $^W; |
144
|
36
|
|
|
36
|
|
285
|
no strict qw(refs); |
|
36
|
|
|
|
|
85
|
|
|
36
|
|
|
|
|
5300
|
|
145
|
|
|
|
|
|
|
|
146
|
36
|
|
|
|
|
149
|
for my $method (@PublicMethods) { |
147
|
504
|
|
|
|
|
720
|
*{"Text::CSV::$method"} = \&{"$module\::$method"}; |
|
504
|
|
|
|
|
1715
|
|
|
504
|
|
|
|
|
1234
|
|
148
|
|
|
|
|
|
|
} |
149
|
36
|
|
|
|
|
320
|
return 1; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |
155
|
|
|
|
|
|
|
__END__ |