File Coverage

blib/lib/Data/Grid/Row.pm
Criterion Covered Total %
statement 15 18 83.3
branch n/a
condition n/a
subroutine 5 8 62.5
pod 3 3 100.0
total 23 29 79.3


line stmt bran cond sub pod time code
1             package Data::Grid::Row;
2              
3 1     1   6 use warnings FATAL => 'all';
  1         2  
  1         35  
4 1     1   5 use strict;
  1         2  
  1         26  
5              
6 1     1   5 use base 'Data::Grid::Container';
  1         1  
  1         69  
7              
8 1     1   5 use overload '@{}' => "cells";
  1         1  
  1         5  
9 1     1   48 use overload '%{}' => "as_hash";
  1         2  
  1         3  
10              
11             =head1 NAME
12              
13             Data::Grid::Row - Row implementation for Data::Grid::Table
14              
15             =head1 VERSION
16              
17             Version 0.01_01
18              
19             =cut
20              
21             our $VERSION = '0.01_01';
22              
23             =head1 SYNOPSIS
24              
25             # CSV files are themselves only a single table, so the list
26             # context assignment here takes the first and only one.
27             my ($table) = Data::Grid->parse('foo.csv')->tables;
28              
29             while (my $row = $table->next) {
30             my @cells = $row->cells;
31             # or
32             @cells = @$row;
33              
34             # or, if column names were supplied somehow:
35              
36             my %cells = $row->as_hash;
37             # or
38             %cells = %$row;
39             }
40              
41             =head1 METHODS
42              
43             =head2 table
44              
45             Retrieve the L object to which this row
46             belongs. Alias for L.
47              
48             =cut
49              
50             sub table {
51 0     0 1   $_[0]->parent;
52             }
53              
54             =head2 cells
55              
56             Retrieve the cells from the row, as an array in list context or
57             arrayref in scalar context. The array dereferencing operator C<@{}> is
58             also overloaded and works like this:
59              
60             my @cells = @$row;
61              
62             =cut
63              
64             sub cells {
65 0     0 1   Carp::croak("This method is a stub; it must be overridden!");
66             }
67              
68             =head2 as_hash
69              
70             If the table has a heading or its columns were designated in the
71             constructor or with L, this method will
72             return the row as key-value pairs in list context and a HASH reference
73             in scalar context. If there is no column spec, this method will
74             generate dummy column names starting from 1, like C, C,
75             etc. It will also fill in the blanks if the column spec is shorter
76             than the actual row. If the column spec is longer, the overhang will
77             be populated with Cs. As well it is worth noting that duplicate
78             keys will be clobbered with the rightmost value at this time, though
79             that behaviour may change. As with the other pertinent methods, the
80             hash dereference operator C<%{}> is overloaded and will behave as
81             such:
82              
83             my %cells = %$row;
84              
85             =cut
86              
87             sub as_hash {
88 0     0 1   my $self = shift;
89             # my @cols = $self->table->columns or Carp::croak(
90             # q{Can't make a hash of cells. The table must have a heading or },
91             # q{the columns must be specified either in the constructor or by },
92             # q{setting them with "columns" in Data::Grid::Table.});
93             # my @cells = $self->cells;
94             }
95              
96             =head1 AUTHOR
97              
98             Dorian Taylor, C<< >>
99              
100             =head1 BUGS
101              
102             Please report any bugs or feature requests to C
103             rt.cpan.org>, or through the web interface at
104             L. I will
105             be notified, and then you'll automatically be notified of progress on
106             your bug as I make changes.
107              
108             =head1 SUPPORT
109              
110             You can find documentation for this module with the perldoc command.
111              
112             perldoc Data::Grid::Row
113              
114              
115             You can also look for information at:
116              
117             =over 4
118              
119             =item * RT: CPAN's request tracker
120              
121             L
122              
123             =item * AnnoCPAN: Annotated CPAN documentation
124              
125             L
126              
127             =item * CPAN Ratings
128              
129             L
130              
131             =item * Search CPAN
132              
133             L
134              
135             =back
136              
137             =head1 SEE ALSO
138              
139             L, L, L,
140             L
141              
142             =head1 LICENSE AND COPYRIGHT
143              
144             Copyright 2010 Dorian Taylor.
145              
146             This program is free software; you can redistribute it and/or modify it
147             under the terms of either: the GNU General Public License as published
148             by the Free Software Foundation; or the Artistic License.
149              
150             See http://dev.perl.org/licenses/ for more information.
151              
152              
153             =cut
154              
155             1; # End of Data::Grid::Row