ORM/Filter/Group.pm

filter: Statementstmt 78.0% 32 / 41 Branchbran 62.5% 5 / 8 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 64.7% 46 / 71 CC 10 SCAR 15.3
CC
10
Cov
70%
add_expr
6.3
_tjoin
6.0
_sql_str
5.4
CRAP 4.6
« ORM/Date.pm ↑ Summary ORM/DbLog.pm »
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 <akimov_alexey@sourceforge.net>
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 5 $VERSION=0.8;
32  
33 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 ▶use overload 'fallback' => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 5 ▶use base 'ORM::Filter';
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 ##
38 ## CONSTRUCTORS
39 ##
40  
41 sub new
42 6 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
43 6 my $class = shift;
44 6 my $op = shift;
45 6 my @arg = @_;
46 6 my $self = bless { op=>$op, arg=>[] }, $class;
47  
48 6 $self->add_expr( @arg );
49 6 return $self;
50 }
51  
52 ##
53 ## PROPERTIES
54 ##
55  
56 sub _sql_str
57 6 ▶{
Subroutine _sql_str: called CC=5 SCAR=16.8
58 6 my $self = shift;
59 6 my %arg = @_;
60 6 my $sql;
61  
62 6 for my $arg ( @{$self->{arg}} )
63 {
64 6 my $add = $arg->_sql_str( tjoin=>$arg{tjoin} );
65 6 ▶ $sql .= " $self->{op} " if( $sql && $add );
Branch: 1 branch
BranchTrueFalseTotal
if $sql and $add 0 6 6
Condition33%1/3
$sql and $add
!ll&&!rl&&r
600
MC/DC0%0/2
$sql and $add
$sql $add
Truth table33%1/3
A and B
A= $sqlB= $add
ABresult
0X0
100
111
66 6 $sql .= $add;
67 }
68  
69 6 ▶ return $sql && "($sql)";
Condition50%1/2
$sql && "($sql)"
!ll
06
MC/DC0%0/1
$sql && "($sql)"
$sql
Truth table50%1/2
A
A= $sql
Aresult
00
11
70 }
71  
72 sub _tjoin
73 0 ▶{
Subroutine _tjoin: not called CC=2 SCAR=17.9
74 0 my $self = shift;
75 0 my $tjoin = ORM::Tjoin->new;
76  
77 0 for my $arg ( @{$self->{arg}} )
78 {
79 0 $tjoin->merge( $arg->_tjoin );
80 }
81  
82 0 return $tjoin;
83 }
84  
85 ##
86 ## METHODS
87 ##
88  
89 sub add_expr
90 6 ▶{
Subroutine add_expr: called CC=5 SCAR=18.3
Pod undocumented
91 6 my $self = shift;
92 6 my @arg = @_;
93  
94 6 ▶ for( my $i=0; $i<@arg; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @arg) 6 6 12
95 {
96 6 ▶ if( ! defined $arg[$i] )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $arg[$i]) { } 0 6 6
elsif (not ref $arg[$i] && $arg[$i]->can('_tjoin')) { } 0 6 6
97 {
98 0 splice @arg, $i, 1;
99 0 $i--;
100 }
101 ▶ elsif( ! ref $arg[$i] || !$arg[$i]->can( '_tjoin' ) )
Condition33%1/3
ref $arg[$i] && $arg[$i]->can('_tjoin')
!ll&&!rl&&r
006
MC/DC0%0/2
ref $arg[$i] && $arg[$i]->can('_tjoin')
ref $arg[$i] $arg[$i]->can('_tjoin')
Truth table33%1/3
A && B
A= ref $arg[$i]B= $arg[$i]->can('_tjoin')
ABresult
0X0
100
111
102 {
103 0 croak "Bad arg #".($i+1).": '$arg[$i]'";
104 }
105 }
106 6 push @{$self->{arg}}, @arg;
107  
108 6 return undef;
109 }
« ORM/Date.pm ↑ Summary ORM/DbLog.pm »