File Coverage

blib/lib/SQL/Object/Interp.pm
Criterion Covered Total %
statement 43 48 89.5
branch 5 8 62.5
condition 5 12 41.6
subroutine 12 12 100.0
pod 5 5 100.0
total 70 85 82.3


line stmt bran cond sub pod time code
1             package SQL::Object::Interp;
2 2     2   48151 use strict;
  2         6  
  2         76  
3 2     2   9 use warnings;
  2         5  
  2         54  
4 2     2   3111 use utf8;
  2         25  
  2         11  
5 2     2   73 use base 'SQL::Object';
  2         4  
  2         1688  
6 2     2   14244 use Exporter qw/import/;
  2         5  
  2         1256  
7            
8             our @EXPORT_OK = qw/isql_obj/;
9            
10             our $VERSION = '0.04';
11            
12             sub isql_obj {
13 5     5 1 4988 require SQL::Interp;
14 5         15584 my ($sql, @args) = SQL::Interp::sql_interp(@_);
15 5         369 my $bind = [@args];
16 5         34 SQL::Object::Interp->new(sql => $sql, bind => $bind);
17             }
18            
19             sub _compose {
20 4     4   134 my ($self, $op, $sql, @bind) = @_;
21            
22 4         16 $self->{sql} = $self->{sql} . " $op " . $sql;
23 4         6 $self->{bind} = [@{$self->{bind}}, @bind];
  4         15  
24 4         17 $self;
25             }
26            
27             sub _no_compose {
28 1     1   44 my ($self, $sql, @bind) = @_;
29 1         2 $self->{sql} = $sql;
30 1         2 $self->{bind} = [@bind];
31 1         3 $self;
32             }
33            
34             sub and {
35 2     2 1 1140 my ($self, @args) = @_;
36 2 100 66     20 if(defined $self->{sql} && $self->{sql} ne ''){
37 1         5 $self->_compose('AND', SQL::Interp::sql_interp(@args));
38             }else{
39 1         3 $self->_no_compose(SQL::Interp::sql_interp(@args));
40             }
41             }
42            
43             sub or {
44 1     1 1 1141 my ($self, @args) = @_;
45 1 50 33     15 if(defined $self->{sql} && $self->{sql} ne ''){
46 1         11 $self->add_parens->_compose('OR', SQL::Interp::sql_interp(@args));
47             }else{
48 0         0 $self->_no_compose(SQL::Interp::sql_interp(@args));
49             }
50             }
51            
52             sub compose_and {
53 1     1 1 28 my ($self, $other) = @_;
54 1 50 33     11 if(defined $self->{sql} && $self->{sql} ne ''){
55 1         3 $self->_compose('AND', $other->{sql}, @{$other->{bind}});
  1         3  
56             }else{
57 0         0 $self->_no_compose($other->{sql}, @{$other->{bind}});
  0         0  
58             }
59             }
60            
61             sub compose_or {
62 1     1 1 26 my ($self, $other) = @_;
63 1 50 33     15 if(defined $self->{sql} && $self->{sql} ne ''){
64 1         6 $self->add_parens->_compose('OR', $other->add_parens->{sql}, @{$other->{bind}});
  1         14  
65             }else{
66 0           $self->_no_compose($other->add_parens->{sql}, @{$other->{bind}});
  0            
67             }
68             }
69            
70            
71             1;
72             __END__