line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::CSV; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
33
|
|
|
33
|
|
1906648
|
use strict; |
|
33
|
|
|
|
|
298
|
|
|
33
|
|
|
|
|
834
|
|
5
|
33
|
|
|
33
|
|
152
|
use Exporter; |
|
33
|
|
|
|
|
48
|
|
|
33
|
|
|
|
|
1055
|
|
6
|
33
|
|
|
33
|
|
165
|
use Carp (); |
|
33
|
|
|
|
|
46
|
|
|
33
|
|
|
|
|
889
|
|
7
|
33
|
|
|
33
|
|
156
|
use vars qw( $VERSION $DEBUG @ISA @EXPORT_OK %EXPORT_TAGS ); |
|
33
|
|
|
|
|
64
|
|
|
33
|
|
|
|
|
2936
|
|
8
|
|
|
|
|
|
|
@ISA = qw( Exporter ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
BEGIN { |
11
|
33
|
|
|
33
|
|
102
|
$VERSION = '2.02'; |
12
|
33
|
|
|
|
|
12527
|
$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.48'; |
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
|
645
|
|
|
645
|
1
|
491629
|
my $proto = shift; |
71
|
645
|
|
100
|
|
|
2396
|
my $class = ref($proto) || $proto; |
72
|
|
|
|
|
|
|
|
73
|
645
|
100
|
|
|
|
1197
|
unless ( $proto ) { # for Text::CSV_XS/PP::new(0); |
74
|
1
|
|
|
|
|
53
|
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
|
644
|
100
|
|
|
|
2133
|
if ( my $obj = $Text::CSV::Worker->new(@_) ) { |
82
|
593
|
|
|
|
|
993
|
$obj->{_MODULE} = $Text::CSV::Worker; |
83
|
593
|
|
|
|
|
1172
|
bless $obj, $class; |
84
|
593
|
|
|
|
|
3614
|
return $obj; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
50
|
|
|
|
|
133
|
return; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub csv { |
94
|
284
|
100
|
100
|
284
|
1
|
45167
|
if (@_ && ref $_[0] eq __PACKAGE__ or ref $_[0] eq __PACKAGE__->backend) { |
|
|
|
66
|
|
|
|
|
95
|
11
|
|
|
|
|
25
|
splice @_, 0, 0, "csv"; |
96
|
|
|
|
|
|
|
} |
97
|
284
|
|
|
|
|
505
|
my $backend = __PACKAGE__->backend; |
98
|
33
|
|
|
33
|
|
240
|
no strict 'refs'; |
|
33
|
|
|
|
|
60
|
|
|
33
|
|
|
|
|
10208
|
|
99
|
284
|
|
|
|
|
411
|
&{"$backend\::csv"}(@_); |
|
284
|
|
|
|
|
1018
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
0
|
0
|
0
|
sub require_xs_version { $XS_Version; } |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub module { |
106
|
561
|
|
|
561
|
0
|
828
|
my $proto = shift; |
107
|
|
|
|
|
|
|
return !ref($proto) ? $Text::CSV::Worker |
108
|
561
|
50
|
|
|
|
1440
|
: 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
|
945
|
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
|
33
|
|
|
33
|
|
68
|
sub _load_pp { _load($Module_PP) } |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _load { |
131
|
33
|
|
|
33
|
|
67
|
my ($module, $version) = @_; |
132
|
33
|
|
50
|
|
|
209
|
$version ||= ''; |
133
|
|
|
|
|
|
|
|
134
|
33
|
50
|
|
|
|
68
|
$Text::CSV::DEBUG and Carp::carp "Load $module."; |
135
|
|
|
|
|
|
|
|
136
|
33
|
|
|
33
|
|
29938
|
eval qq| use $module $version |; |
|
33
|
|
|
|
|
99
|
|
|
33
|
|
|
|
|
1048
|
|
|
33
|
|
|
|
|
2052
|
|
137
|
|
|
|
|
|
|
|
138
|
33
|
50
|
|
|
|
139
|
return if $@; |
139
|
|
|
|
|
|
|
|
140
|
33
|
|
|
|
|
295
|
push @Text::CSV::ISA, $module; |
141
|
33
|
|
|
|
|
87
|
$Text::CSV::Worker = $module; |
142
|
|
|
|
|
|
|
|
143
|
33
|
|
|
|
|
319
|
local $^W; |
144
|
33
|
|
|
33
|
|
220
|
no strict qw(refs); |
|
33
|
|
|
|
|
76
|
|
|
33
|
|
|
|
|
3996
|
|
145
|
|
|
|
|
|
|
|
146
|
33
|
|
|
|
|
94
|
for my $method (@PublicMethods) { |
147
|
462
|
|
|
|
|
520
|
*{"Text::CSV::$method"} = \&{"$module\::$method"}; |
|
462
|
|
|
|
|
1363
|
|
|
462
|
|
|
|
|
871
|
|
148
|
|
|
|
|
|
|
} |
149
|
33
|
|
|
|
|
219
|
return 1; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |
155
|
|
|
|
|
|
|
__END__ |