line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Package::CSV; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Data::Package::CSV - A Data::Package class for CSV data using Parse::CSV |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
The B package provides a subclass of |
12
|
|
|
|
|
|
|
L that provides data from a CSV file by integrating |
13
|
|
|
|
|
|
|
with L. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 METHODS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
2
|
|
21872
|
use 5.005; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
76
|
|
20
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
69
|
|
21
|
2
|
|
|
2
|
|
20
|
use base 'Data::Package::File'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1907
|
|
22
|
2
|
|
|
2
|
|
76863
|
use Parse::CSV (); |
|
2
|
|
|
|
|
57840
|
|
|
2
|
|
|
|
|
70
|
|
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
2
|
|
26
|
use vars qw{$VERSION}; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
105
|
|
25
|
|
|
|
|
|
|
BEGIN { |
26
|
2
|
|
|
2
|
|
582
|
$VERSION = '1.01'; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub import { |
30
|
2
|
50
|
|
2
|
|
616
|
return 1 if $_[0] eq __PACKAGE__; |
31
|
0
|
|
|
|
|
0
|
return shift->SUPER::import(@_); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
##################################################################### |
39
|
|
|
|
|
|
|
# Data::Package::CSV Methods |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=pod |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 csv_options |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
The B method is the most direct method, with full control |
46
|
|
|
|
|
|
|
over the creation of the L object. If a fully compliant options |
47
|
|
|
|
|
|
|
hash is returned (as a list) then no other methods need to be defined. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
The list returned by the B method will be passed directly to |
50
|
|
|
|
|
|
|
the L constructor. Read the documentation for L for |
51
|
|
|
|
|
|
|
more details on what you should return to match your data. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
By default, the null list is return, specifying entirely default options |
54
|
|
|
|
|
|
|
to the L constructor (array mode) and not specifying any filters |
55
|
|
|
|
|
|
|
or parsing variations. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
If it list that is returned does not have either a data source (either a |
58
|
|
|
|
|
|
|
C param or C param) then the C method for the parent |
59
|
|
|
|
|
|
|
class will be called to locate a file. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub csv_options { |
64
|
2
|
|
|
2
|
1
|
6
|
return (); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
##################################################################### |
72
|
|
|
|
|
|
|
# Data::Package Methods |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _provides { |
75
|
7
|
|
|
7
|
|
50637
|
my @provides = shift->SUPER::_provides(@_); |
76
|
7
|
|
|
|
|
3026
|
return ( 'Parse::CSV', @provides ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub __as_Parse_CSV { |
80
|
4
|
|
33
|
4
|
|
1076
|
my $class = ref($_[0]) || $_[0]; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Get the main options |
83
|
4
|
|
|
|
|
20
|
my %options = $class->csv_options; |
84
|
4
|
50
|
33
|
|
|
54
|
unless ( $options{handle} or $options{file} ) { |
85
|
4
|
|
|
|
|
11
|
delete $options{file}; |
86
|
4
|
|
|
|
|
8
|
delete $options{handle}; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Locate the data |
89
|
4
|
|
|
|
|
32
|
my $file = $class->file; |
90
|
4
|
50
|
|
|
|
8539
|
if ( $file ) { |
91
|
4
|
|
|
|
|
20
|
$options{file} = $class->file; |
92
|
4
|
|
|
|
|
2515
|
delete $options{handle}; |
93
|
|
|
|
|
|
|
} else { |
94
|
0
|
|
|
|
|
0
|
die "No CSV file found for $class"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Create the parser object |
99
|
4
|
|
|
|
|
37
|
my $parse_csv = Parse::CSV->new( %options ); |
100
|
4
|
50
|
|
|
|
1560
|
unless ( $parse_csv ) { |
101
|
0
|
|
|
|
|
0
|
die "Failed to create Parse::CSV object for $class"; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
4
|
|
|
|
|
19
|
return $parse_csv; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=pod |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SUPPORT |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Bugs should always be submitted via the CPAN bug tracker. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
L |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
For other issues, contact the maintainer |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 AUTHOR |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Adam Kennedy Eadamk@cpan.orgE |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 COPYRIGHT |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Copyright 2007 Adam Kennedy. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This program is free software; you can redistribute |
128
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
The full text of the license can be found in the |
131
|
|
|
|
|
|
|
LICENSE file included with this module. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |