line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Grid::Table; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
8
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
4
|
1
|
|
|
1
|
|
19
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use base 'Data::Grid::Container'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
697
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
7
|
use overload '<>' => "next"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
9
|
1
|
|
|
1
|
|
61
|
use overload '@{}' => "rows"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Data::Grid::Table - A table implementation for Data::Grid |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.01_01 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.01_01'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $grid = Data::Grid->parse('arbitrary.csv'); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Just take the first one, since a CSV will only have one table. |
29
|
|
|
|
|
|
|
my ($table) = $grid->tables; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
while (my $row = $table->next) { |
32
|
|
|
|
|
|
|
# do some stuff |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# or |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
while (my $row = <$table>) { |
38
|
|
|
|
|
|
|
# ... |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# or |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my @rows = $table->rows; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# or |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my @rows = @$table; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 METHODS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 next |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Retrieves the next row in the table or C when it reaches the |
54
|
|
|
|
|
|
|
end. This method L by a driver subclass. The |
55
|
|
|
|
|
|
|
iteration operator C<<>> is also overloaded for table objects, so you |
56
|
|
|
|
|
|
|
can use it like this: |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
while (my $row = <$table>) { ... |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub next { |
63
|
0
|
|
|
0
|
1
|
|
Carp::croak("This method is a stub; it must be overridden!"); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 first |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Returns the first row in the table, and is equivalent to calling |
69
|
|
|
|
|
|
|
L and then L. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub first { |
74
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
75
|
0
|
|
|
|
|
|
$self->rewind; |
76
|
0
|
|
|
|
|
|
$self->next; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 rewind |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Sets the table's cursor back to the first row. Returns the previous |
82
|
|
|
|
|
|
|
position, beginning at zero. This method I by a |
83
|
|
|
|
|
|
|
driver subclass. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub rewind { |
88
|
0
|
|
|
0
|
1
|
|
Carp::croak("This method is a stub; it must be overridden!"); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 rows |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Retrieves an array of rows all at once, or if taken in scalar context, |
94
|
|
|
|
|
|
|
an array reference. This method overloads the array dereferencing |
95
|
|
|
|
|
|
|
operator C<@{}>, so you can use it like this: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my @rows = @$table; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub rows { |
102
|
0
|
|
|
0
|
1
|
|
my ($self, @rows) = @_; |
103
|
|
|
|
|
|
|
#my @rows; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$self->rewind; |
106
|
0
|
|
|
|
|
|
while (my $row = $self->next) { |
107
|
0
|
|
|
|
|
|
push @rows, $row; |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
|
$self->rewind; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
wantarray ? @rows : \@rows; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 columns |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
0
|
1
|
|
sub columns { |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 width |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Gets the width, in columns, of the table. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 height |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Gets the height, in rows, of the table. Careful, for drivers that only |
130
|
|
|
|
|
|
|
do sequential access, this means iterating over the whole set, so you |
131
|
|
|
|
|
|
|
might as well. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub height { |
136
|
0
|
|
|
0
|
1
|
|
scalar @{$_[0]->rows}; |
|
0
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 as_string |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Serializes the table into a string and returns the result. Currently |
142
|
|
|
|
|
|
|
unimplemented. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
#sub as_string { |
147
|
|
|
|
|
|
|
# |
148
|
|
|
|
|
|
|
#} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 as_data_table |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Returns a new Data::Table object for compatibility. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub as_data_table { |
157
|
0
|
|
|
0
|
1
|
|
require Data::Table; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 AUTHOR |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Dorian Taylor, C<< >> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 BUGS |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Please report any bugs or feature requests to C
|
167
|
|
|
|
|
|
|
rt.cpan.org>, or through the web interface at |
168
|
|
|
|
|
|
|
L. I will |
169
|
|
|
|
|
|
|
be notified, and then you'll automatically be notified of progress on |
170
|
|
|
|
|
|
|
your bug as I make changes. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 SUPPORT |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
perldoc Data::Grid::Table |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
You can also look for information at: |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=over 4 |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
L |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
L |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item * CPAN Ratings |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
L |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * Search CPAN |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
L |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=back |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 SEE ALSO |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
L, L, L, |
203
|
|
|
|
|
|
|
L |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Copyright 2010 Dorian Taylor. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
210
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
211
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
1; # End of Data::Grid::Table |