ORM/Order.pm

filter: Statementstmt 67.5% 27 / 40 Branchbran 42.8% 6 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 4 totaltotal 57.8% 37 / 64 CC 11 SCAR 22.6
CC
11
Cov
61%
new
16.9
_tjoin
3.0
sql_order_by
2.0
CRAP 9.6
« ORM/Db/DBI/SQLite.pm ↑ Summary ORM/Meta/ORM/Date.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::Order;
30  
31 5 $VERSION=0.8;
32  
33 5 ▶use ORM::Metaprop;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 ## use: $order = $class->new
36 ## (
37 ## (
38 ## ORM::Metaprop
39 ## | [ORM::Metaprop, ('ASC'|'DESC')]
40 ## ),
41 ## ...
42 ## )
43 ##
44 ## OR
45 ##
46 ## $order = $class->new( STRING )
47 ##
48 sub new
49 1 ▶{
Subroutine new: called CC=8 SCAR=28.3
Pod undocumented
50 1 my $class = shift;
51 1 my @order;
52  
53 1 ▶ if( ref $_[0] )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 1 0 1
54 {
55 1 @order = @_;
56 # Validating $arg{order}
57 1 ▶ for( my $i=0; $i<@order; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @order) 1 1 2
58 {
59 1 ▶ if( ref $order[$i] eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $order[$i] eq 'ARRAY') { } 0 1 1
60 {
61 0 ▶ $order[$i][1] = ( $order[$i][1] =~ /^DESC$/i ) ? 'DESC' : 'ASC';
Branch: 1 branch
BranchTrueFalseTotal
$order[$i][1] =~ /^DESC$/i ? : 0 0 0
62 }
63 else
64 {
65 1 $order[$i] = [ $order[$i], 'ASC' ];
66 }
67 }
68 }
69 else
70 {
71 0 my %arg = @_;
72 0 my $obj_class = $arg{class};
73 0 my $order_str = $arg{sort_str};
74  
75 0 for my $field ( split /[\,]+/, $order_str )
76 {
77 0 my( $prop, $dir ) = split /\s/, $field;
78 0 ▶ push @order,
Branch: 1 branch
BranchTrueFalseTotal
$dir =~ /^DESC$/i ? : 0 0 0
79 [
80 $obj_class->M->_prop( $prop ),
81 ( ( $dir =~ /^DESC$/i ) ? 'DESC' : 'ASC' ),
82 ];
83 }
84 }
85 1 ▶ return scalar(@order) ? ( bless { order=>\@order }, $class ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
scalar @order ? : 1 0 1
86 }
87  
88 sub _tjoin
89 1 ▶{
Subroutine _tjoin: called CC=3 SCAR=11.0
90 1 my $self = shift;
91  
92 1 ▶ if( !$self->{tjoin} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"tjoin"}) 1 0 1
93 {
94 1 $self->{tjoin} = ORM::Tjoin->new;
95 1 for my $prop ( @{$self->{order}} )
96 {
97 1 $self->{tjoin}->merge( $prop->[0]->_tjoin );
98 }
99 }
100  
101 1 return $self->{tjoin};
102 }
103  
104 sub sql_order_by
105 1 ▶{
Subroutine sql_order_by: called CC=2 SCAR=6.9
Pod undocumented
106 1 my $self = shift;
107 1 my %arg = @_;
108 1 my $sql;
109  
110 1 for my $prop ( @{$self->{order}} )
111 {
112 1 $sql .= $prop->[0]->_sql_str( tjoin=>$arg{tjoin} ) .' '. $prop->[1] .',';
113 }
114 1 chop $sql;
115  
116 1 return $sql;
117 }
118  
119 sub cond
120 0 ▶{
Subroutine cond: not called CC=1 SCAR=6.9
Pod undocumented
121 0 my $self = shift;
122 0 my $index = shift;
123  
124 0 return $self->{order}[$index];
125 }
126  
127 sub conds_amount
128 0 ▶{
Subroutine conds_amount: not called CC=1 SCAR=6.9
Pod undocumented
129 0 my $self = shift;
130 0 return scalar @{$self->{order}};
131 }
« ORM/Db/DBI/SQLite.pm ↑ Summary ORM/Meta/ORM/Date.pm »