File Coverage

blib/lib/ORM/Filter/Group.pm
Criterion Covered Total %
statement 31 40 77.5
branch 3 6 50.0
condition 3 9 33.3
subroutine 6 7 85.7
pod 0 2 0.0
total 43 64 67.1


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::Group;
30              
31             $VERSION=0.8;
32              
33 5     5   28 use Carp;
  5         9  
  5         420  
34 5     5   28 use overload 'fallback' => 1;
  5         9  
  5         28  
35 5     5   281 use base 'ORM::Filter';
  5         9  
  5         2268  
36              
37             ##
38             ## CONSTRUCTORS
39             ##
40              
41             sub new
42             {
43 6     6 0 11 my $class = shift;
44 6         8 my $op = shift;
45 6         22 my @arg = @_;
46 6         36 my $self = bless { op=>$op, arg=>[] }, $class;
47              
48 6         24 $self->add_expr( @arg );
49 6         20 return $self;
50             }
51              
52             ##
53             ## PROPERTIES
54             ##
55              
56             sub _sql_str
57             {
58 6     6   9 my $self = shift;
59 6         15 my %arg = @_;
60 6         8 my $sql;
61              
62 6         8 for my $arg ( @{$self->{arg}} )
  6         19  
63             {
64 6         26 my $add = $arg->_sql_str( tjoin=>$arg{tjoin} );
65 6 50 33     26 $sql .= " $self->{op} " if( $sql && $add );
66 6         19 $sql .= $add;
67             }
68              
69 6   33     36 return $sql && "($sql)";
70             }
71              
72             sub _tjoin
73             {
74 0     0   0 my $self = shift;
75 0         0 my $tjoin = ORM::Tjoin->new;
76              
77 0         0 for my $arg ( @{$self->{arg}} )
  0         0  
78             {
79 0         0 $tjoin->merge( $arg->_tjoin );
80             }
81              
82 0         0 return $tjoin;
83             }
84              
85             ##
86             ## METHODS
87             ##
88              
89             sub add_expr
90             {
91 6     6 0 11 my $self = shift;
92 6         12 my @arg = @_;
93              
94 6         21 for( my $i=0; $i<@arg; $i++ )
95             {
96 6 50 33     81 if( ! defined $arg[$i] )
    50          
97             {
98 0         0 splice @arg, $i, 1;
99 0         0 $i--;
100             }
101             elsif( ! ref $arg[$i] || !$arg[$i]->can( '_tjoin' ) )
102             {
103 0         0 croak "Bad arg #".($i+1).": '$arg[$i]'";
104             }
105             }
106 6         17 push @{$self->{arg}}, @arg;
  6         91  
107              
108 6         14 return undef;
109             }