File Coverage

blib/lib/DBIx/Romani/ResultSet.pm
Criterion Covered Total %
statement 9 37 24.3
branch 0 8 0.0
condition n/a
subroutine 3 9 33.3
pod 0 6 0.0
total 12 60 20.0


line stmt bran cond sub pod time code
1              
2             package DBIx::Romani::ResultSet;
3              
4 1     1   5 use strict;
  1         2  
  1         40  
5              
6 1     1   5 use constant FETCHMODE_ASSOC => 1;
  1         2  
  1         68  
7 1     1   5 use constant FETCHMODE_NUM => 2;
  1         1  
  1         405  
8              
9             sub new
10             {
11 0     0 0   my $class = shift;
12 0           my $args = shift;
13              
14 0           my $conn;
15             my $sth;
16 0           my $mode;
17              
18 0 0         if ( ref($conn) eq 'HASH' )
19             {
20 0           $conn = $args->{conn};
21 0           $sth = $args->{sth};
22 0           $mode = $args->{fetchmode};
23             }
24             else
25             {
26 0           $conn = $args;
27 0           $sth = shift;
28 0           $mode = shift;
29             }
30              
31 0 0         if ( not defined $mode )
32             {
33 0           $mode = FETCHMODE_ASSOC;
34             }
35              
36 0           my $self = {
37             conn => $conn,
38             sth => $sth,
39             row => undef,
40             mode => $mode,
41             };
42              
43 0           bless $self, $class;
44 0           return $self;
45             }
46              
47 0     0 0   sub get_conn { return shift->{conn}; }
48 0     0 0   sub get_row { return shift->{row}; }
49 0     0 0   sub get_fetchmode { return shift->{mode}; }
50              
51             sub next
52             {
53 0     0 0   my $self = shift;
54              
55 0 0         if ( $self->get_fetchmode() == FETCHMODE_NUM )
56             {
57 0           $self->{row} = $self->{sth}->fetchrow_arrayref();
58             }
59             else
60             {
61 0           $self->{row} = $self->{sth}->fetchrow_hashref();
62             }
63              
64             # return true if we still have data
65 0           return defined( $self->{row} );
66             }
67              
68             sub get
69             {
70 0     0 0   my ($self, $column) = @_;
71              
72 0 0         if ( $self->get_fetchmode() == FETCHMODE_NUM )
73             {
74 0           return $self->{row}->[$column];
75             }
76             else
77             {
78 0           return $self->{row}->{$column};
79             }
80             }
81              
82              
83             # TODO: implement these:
84             #
85             # TODO: Or, maybe, I could provide these with an AUTOLOAD and then if
86             # the child class overrides it, then cool. Otherwise just get().
87             #
88             # * sub get_blob($column)
89             # * sub get_clob($column)
90             # * sub get_date($column)
91             # * sub get_time($column)
92             # * sub get_timestamp($column)
93              
94             1;
95