ORM/Base.pm

filter: Statementstmt 98.3% 59 / 60 Branchbran 65.6% 21 / 32 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 86.4% 89 / 103 CC 20 SCAR 28.5
CC
20
Cov
86%
import
21.3
BEGIN
1.0
BEGIN
1.0
CRAP 17.3
« ORM/Db/DBI.pm ↑ Summary ORM/Broken.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::Base;
30  
31 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 3 $VERSION = 0.8;
34  
35 3 my %require;
36 my %loaded;
37 3 my $active = 0;
38 3 my $debug = 0;
39  
40 sub import
41 10 ▶{
Subroutine import: called CC=20 SCAR=30.6
42 10 my $class = shift;
43 10 my $base = shift;
44 10 my %arg = @_;
45 10 my $derived = caller 0;
46 10 my $i_am_active;
47  
48 10 ▶ unless( $active )
Branch: 1 branch
BranchTrueFalseTotal
unless ($active) 4 6 10
49 {
50 4 ▶ print STDERR "***** Start loading *****\n" if( $debug );
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 4 4
51 4 $active = 1;
52 4 $i_am_active = 1;
53 }
54  
55 10 my $eval = "package $derived; use base $base; ";
56  
57 10 ▶ if( $arg{i_am_history} )
Branch: 1 branch
BranchTrueFalseTotal
if ($arg{"i_am_history"}) 2 8 10
58 {
59 2 $eval .= 'do \'ORM/History.pm\';';
60 2 $arg{history_is_enabled} = 0;
61 }
62  
63 3 ▶ eval $eval;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
64
65 10 ▶ croak "Failed to load package $base\n$@" if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 10 10
66 10 $loaded{$base} = 1;
67 10 $loaded{$derived} = 1;
68 10 ▶ print STDERR " Loading class $derived\n" if( $debug );
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 10 10
69  
70 10 my @require = $base->_derive( derived_class=>$derived, %arg );
71 9 ▶ if( $derived->_history_class && !$loaded{$derived->_history_class} )
Branch: 1 branch
BranchTrueFalseTotal
if ($derived->_history_class and not $loaded{$derived->_history_class}) 5 4 9
Condition66%2/3
$derived->_history_class and not $loaded{$derived->_history_class}
!ll&&!rl&&r
045
MC/DC50%1/2
$derived->_history_class and not $loaded{$derived->_history_class}
$derived->_history_class not $loaded{$derived->_history_class}
Truth table66%2/3
A and not(B)
A= $derived->_history_classB= not $loaded{$derived->_history_class}
ABresult
0X0
100
111
72 {
73 5 push @require, $derived->_history_class;
74 }
75 9 for my $module ( @require )
76 {
77 9 ▶ if( $loaded{$module} )
Branch: 2 branches
BranchTrueFalseTotal
if ($loaded{$module}) { } 0 9 9
elsif ($require{$module}) { } 1 8 9
78 {
79 0 ▶ print STDERR " $derived requested $module (already loaded)\n" if( $debug );
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
80 }
81 elsif( $require{$module} )
82 {
83 1 ▶ print STDERR " $derived requested $module (already in queue)\n" if( $debug );
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
84 }
85 else
86 {
87 8 ▶ print STDERR " $derived requested $module (queued)\n" if( $debug );
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 8 8
88 8 $require{$module} = 1;
89 }
90 }
91  
92 9 ▶ if( $i_am_active )
Branch: 1 branch
BranchTrueFalseTotal
if ($i_am_active) 3 6 9
93 {
94 3 ▶ while( %require )
Branch: 1 branch
BranchTrueFalseTotal
if (%require) 5 3 8
95 {
96 5 my $load;
97  
98 5 for my $module ( keys %require )
99 {
100 7 $loaded{$module} = 1;
101 7 $load .= "require $module; ";
102 }
103  
104 5 %require = ();
105 5 ▶ print STDERR "Loading queued: $load\n" if( $debug );
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 5 5
106 5 eval $load;
107 5 ▶ croak "Failed to load packages: $load\n$@" if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 5 5
108 }
109 3 %loaded = ();
110 3 $active = 0;
111 3 ▶ print STDERR "***** Finish loading *****\n\n" if( $debug );
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 3 3
112 }
113 }
114  
115 3 1;
« ORM/Db/DBI.pm ↑ Summary ORM/Broken.pm »