ORM/StatResultSet.pm

filter: Statementstmt 72.9% 27 / 37 Branchbran 50.0% 6 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 5 totaltotal 60.0% 39 / 65 CC 10 SCAR 19.9
CC
10
Cov
67%
next
10.2
preview
6.0
class
2.0
CRAP 7.3
« ORM/Tjoin.pm ↑ Summary ORM/Ta.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::StatResultSet;
30  
31 5 ▶use ORM;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 5 $VERSION = 0.8;
34  
35 ##
36 ## CONSTRUCTORS
37 ##
38  
39 ## use: $result_set = ORM::StatResultSet->new
40 ## (
41 ## class => string,
42 ## result => ORM::DbResultSet,
43 ## preload => HASH,
44 ## conv => HASH,
45 ## lazy_load => boolean,
46 ## );
47 ##
48 sub new
49 1 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
50 1 my $class = shift;
51 1 my %arg = @_;
52  
53 bless
54 {
55 class => $arg{class},
56 result => $arg{result},
57 preload => $arg{preload},
58 conv => $arg{conv},
59 lazy_load => $arg{lazy_load},
60 1 }, $class;
61 }
62  
63 ##
64 ## PROPERTIES
65 ##
66  
67 0 ▶sub class { $_[0]->{class}; }
Subroutine class: not called CC=1 SCAR=6.9
Pod undocumented
68  
69 sub next
70 2 ▶{
Subroutine next: called CC=9 SCAR=23.2
Pod undocumented
71 2 my $self = shift;
72 2 my %arg = @_;
73 2 my $res;
74 my $error;
75  
76 2 ▶ if( exists $self->{preview} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'preview'}) { } 0 2 2
77 {
78 0 $res = $self->{preview};
79 0 delete $self->{preview};
80 }
81 else
82 {
83 2 ▶ my $pre_res = $self->{result} && $self->{result}->next_row;
Condition66%2/3
$self->{'result'} && $self->{'result'}->next_row
!ll&&!rl&&r
011
MC/DC50%1/2
$self->{'result'} && $self->{'result'}->next_row
$self->{'result'} $self->{'result'}->next_row
Truth table66%2/3
A && B
A= $self->{'result'}B= $self->{'result'}->next_row
ABresult
0X0
100
111
84 2 ▶ return undef unless( defined $pre_res );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pre_res 1 1 2
85  
86 1 $error = ORM::Error->new;
87  
88 # Convert raw values to objects
89 1 for my $name ( keys %{$self->{conv}} )
90 {
91 2 ▶ if( !$self->{conv}{$name} )
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'conv'}{$name}) { } 0 2 2
elsif ($self->{'preload'}{$name}) { } 2 0 2
92 {
93 0 $res->{$name} = $pre_res->{$name};
94 }
95 elsif( $self->{preload}{$name} )
96 {
97 2 $res->{$name} = $self->{conv}{$name}->_cache->get( $pre_res->{$name}, 0 );
98  
99 2 ▶ unless( $res->{$name} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{$name}) 2 0 2
100 {
101 2 my %prop;
102  
103 2 for my $prop_name ( $self->{conv}{$name}->_all_props )
104 {
105 13 $prop{$prop_name} = $pre_res->{"_${name} ${prop_name}"};
106 }
107 2 $prop{id} = $pre_res->{$name};
108  
109 $res->{$name} = $self->{conv}{$name}->_find_constructor
110 (
111 \%prop,
112 2 $self->{conv}{$name}->_db_tables_ref,
113 );
114  
115 2 $self->{conv}{$name}->_cache->add( $res->{$name} );
116 }
117 }
118 else
119 {
120 $res->{$name} = $self->{conv}{$name}->__ORM_new_db_value
121 (
122 value => $pre_res->{$name},
123 error => $error,
124 lazy_load => $self->{lazy_load},
125 0 );
126 }
127 }
128  
129 1 $error->upto( $arg{error} );
130 }
131  
132 1 return $res;
133 }
134  
135 sub preview
136 0 ▶{
Subroutine preview: not called CC=2 SCAR=17.9
Pod undocumented
137 0 my $self = shift;
138  
139 0 ▶ $self->{preview} = $self->next( @_ ) unless( exists $self->{preview} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"preview"} 0 0 0
140 0 return $self->{preview};
141 }
142  
143 sub amount
144 0 ▶{
Subroutine amount: not called CC=1 SCAR=6.9
Pod undocumented
145 0 my $self = shift;
146  
147 0 $self->{result}->rows;
148 }
« ORM/Tjoin.pm ↑ Summary ORM/Ta.pm »