File Coverage

blib/lib/ORM/Filter/Cmp.pm
Criterion Covered Total %
statement 21 23 91.3
branch 5 12 41.6
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 31 41 75.6


line stmt bran cond sub pod time code
1             #
2             # DESCRIPTION
3             # PerlORM - Object relational mapper (ORM) for Perl. PerlORM is Perl
4             # library that implements object-relational mapping. Its features are
5             # much similar to those of Java's Hibernate library, but interface is
6             # much different and easier to use.
7             #
8             # AUTHOR
9             # Alexey V. Akimov
10             #
11             # COPYRIGHT
12             # Copyright (C) 2005-2006 Alexey V. Akimov
13             #
14             # This library is free software; you can redistribute it and/or
15             # modify it under the terms of the GNU Lesser General Public
16             # License as published by the Free Software Foundation; either
17             # version 2.1 of the License, or (at your option) any later version.
18             #
19             # This library is distributed in the hope that it will be useful,
20             # but WITHOUT ANY WARRANTY; without even the implied warranty of
21             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22             # Lesser General Public License for more details.
23             #
24             # You should have received a copy of the GNU Lesser General Public
25             # License along with this library; if not, write to the Free Software
26             # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27             #
28              
29             package ORM::Filter::Cmp;
30              
31             $VERSION=0.8;
32              
33 5     5   45 use overload 'fallback' => 1;
  5         10  
  5         37  
34 5     5   281 use base 'ORM::Filter';
  5         9  
  5         2588  
35              
36             ##
37             ## CONSTRUCTORS
38             ##
39              
40             sub new
41             {
42 12     12 0 22 my $class = shift;
43 12         51 my $self = { op => $_[0] };
44              
45 12 50       61 if( UNIVERSAL::isa( $_[1], 'ORM::Expr' ) )
46             {
47 12         38 $self->{arg1} = $_[1];
48             }
49             else
50             {
51 0 0       0 $self->{arg1} = ( ref $_[1] ? $_[1]->__ORM_db_value : $_[1] );
52             }
53              
54 12 50       59 if( UNIVERSAL::isa( $_[2], 'ORM::Expr' ) )
55             {
56 0         0 $self->{arg2} = $_[2];
57             }
58             else
59             {
60 12 50       60 $self->{arg2} = ( ref $_[2] ? $_[2]->__ORM_db_value : $_[2] );
61             }
62              
63 12         148 return bless $self, $class;
64             }
65              
66             sub _sql_str
67             {
68 12     12   22 my $self = shift;
69 12         29 my %arg = @_;
70              
71             return
72 12         156 '(' . $self->scalar2sql( $self->{arg1}, $arg{tjoin} )
73             . " $self->{op} "
74             . $self->scalar2sql( $self->{arg2}, $arg{tjoin} ) . ')';
75             }
76              
77             sub _tjoin
78             {
79 6     6   13 my $self = shift;
80 6         26 my $tjoin = ORM::Tjoin->new;
81              
82 6 50       83 $tjoin->merge( $self->{arg1}->_tjoin ) if( ref $self->{arg1} );
83 6 50       28 $tjoin->merge( $self->{arg2}->_tjoin ) if( ref $self->{arg2} );
84              
85 6         32 return $tjoin;
86             }