File Coverage

blib/lib/Mojo/PgX/Cursor/Cursor.pm
Criterion Covered Total %
statement 3 23 13.0
branch 0 10 0.0
condition 0 14 0.0
subroutine 1 5 20.0
pod 3 3 100.0
total 7 55 12.7


line stmt bran cond sub pod time code
1             package Mojo::PgX::Cursor::Cursor;
2              
3             require UUID::Tiny;
4              
5 1     1   26796 use Mojo::Base -base;
  1         4  
  1         7  
6              
7             has [qw(bind db name query)];
8              
9             sub DESTROY {
10 0     0     my $self = shift;
11 0 0 0       if ($self->{close} && $self->db && $self->db->ping) { $self->close }
  0   0        
12             }
13              
14             sub close {
15 0     0 1   my $self = shift;
16 0           my $query = sprintf('close %s', $self->db->dbh->quote_identifier($self->name));
17 0 0         $self->db->query($query) if delete $self->{close};
18             }
19              
20             sub fetch {
21 0     0 1   my $self = shift;
22 0 0         my $cb = ref $_[-1] eq 'CODE' ? pop : undef;
23 0   0       my $fetch = shift || 100;
24 0           my $query = sprintf('fetch %s from %s', $fetch, $self->db->dbh->quote_identifier($self->name));
25 0           my @query_params = $query;
26 0 0         push @query_params, $cb if $cb;
27 0           return $self->db->query(@query_params);
28             }
29              
30             sub new {
31 0     0 1   my $self = shift->SUPER::new(
32             bind => [],
33             name => UUID::Tiny::create_uuid_as_string(UUID::Tiny::UUID_V4()),
34             @_,
35             );
36 0 0 0       return unless defined $self->db
      0        
37             and defined $self->query and length $self->query;
38 0           my $query = sprintf('declare %s cursor with hold for %s',
39             $self->db->dbh->quote_identifier($self->name), $self->query);
40 0           $self->db->query($query, @{$self->bind});
  0            
41 0           $self->{close} = 1;
42 0           return $self;
43             }
44              
45             1;
46             __END__