ORM/DbLog.pm

filter: Statementstmt 60.6% 40 / 66 Branchbran 41.6% 10 / 24 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 50.0% 7 / 14 Podpod 0.0% 0 / 12 totaltotal 51.2% 62 / 121 CC 14 SCAR 14.8
CC
14
Cov
57%
text
12.0
new
6.3
_push_to_memory_log
4.9
CRAP 4.4
« ORM/Filter/Group.pm ↑ Summary ORM/Error.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::DbLog;
30  
31 4 $VERSION=0.8;
32  
33 4 ▶use ORM::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 4 my $STDERR;
36 my $STDOUT;
37 4 my $FILE;
38 4 my $MEM_LOG_SIZE = 0;
39 4 my @MEM_LOG;
40  
41 ##
42 ## CONSTRUCTOR
43 ##
44  
45 sub new
46 102 ▶{
Subroutine new: called CC=6 SCAR=18.4
Pod undocumented
47 102 my $class = shift;
48 102 my %arg = @_;
49 102 my $self;
50 my $caller;
51  
52 102 for( my $i=1; ; $i++ )
53 {
54 389 $caller = (caller $i )[3];
55 389 ▶ last if( ! defined $caller || ( substr $caller, 0, 9 ) ne 'ORM::Db::' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $caller or substr($caller, 0, 9) ne "ORM::Db::" 102 287 389
Condition100%3/3
not defined $caller or substr($caller, 0, 9) ne "ORM::Db::"
l!l&&r!l&&!r
1191287
MC/DC100%2/2
not defined $caller or substr($caller, 0, 9) ne "ORM::Db::"
not defined $caller substr($caller, 0, 9) ne "ORM::Db::"
Truth table100%3/3
not(A) or B
A= not defined $callerB= substr($caller, 0, 9) ne "ORM::Db::"
ABresult
1X1
011
000
56 }
57  
58 102 $self->{sql} = $arg{sql};
59 102 $self->{error} = $arg{error};
60 102 $self->{date} = ORM::Datetime->current;
61 102 $self->{caller} = $caller;
62  
63 102 bless $self, $class;
64  
65 102 $class->_push_to_memory_log( $self );
66  
67 102 ▶ if( $class->write_to_stderr )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->write_to_stderr) 0 102 102
68 {
69 0 print STDERR $self->text;
70 }
71  
72 102 ▶ if( $class->write_to_stdout )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->write_to_stdout) 0 102 102
73 {
74 0 print $self->text;
75 }
76  
77 102 ▶ if( $class->write_to_file )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->write_to_file) 0 102 102
78 {
79 0 $class->write_to_file->print( $self->text );
80 }
81  
82 102 return $self;
83 }
84  
85 ##
86 ## OBJECT PROPERTIES
87 ##
88  
89 0 ▶sub sql { $_[0]->{sql}; }
Subroutine sql: not called CC=1 SCAR=6.9
Pod undocumented
90 0 ▶sub error { $_[0]->{error}; }
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
91 0 ▶sub date { $_[0]->{date}; }
Subroutine date: not called CC=1 SCAR=6.9
Pod undocumented
92 0 ▶sub caller { $_[0]->{caller}; }
Subroutine caller: not called CC=1 SCAR=6.9
Pod undocumented
93  
94 sub text
95 0 ▶{
Subroutine text: not called CC=3 SCAR=24.8
Pod undocumented
96 0 my $self = shift;
97 0 my $str;
98  
99 0 $str .= "--------------------------\n";
100 0 ▶ $str .= '['.$self->date->datetime_str.']: '.$self->caller.': '.( $self->error ? 'FAILED' : 'Success' )."\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->error ? : 0 0 0
101 0 $str .= $self->sql . "\n";
102 0 ▶ $str .= 'ERROR: ' . $self->error if( $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if $self->error 0 0 0
103 0 $str .= "\n";
104  
105 0 return $str;
106 }
107  
108 ##
109 ## CLASS METHODS
110 ##
111  
112 sub write_to_stderr
113 102 ▶{
Subroutine write_to_stderr: called CC=2 SCAR=7.6
Pod undocumented
114 102 my $class = shift;
115  
116 0 ▶ if( @_ ) { $STDERR = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 102 102
117 102 return $STDERR;
118 }
119  
120 sub write_to_stdout
121 102 ▶{
Subroutine write_to_stdout: called CC=2 SCAR=7.6
Pod undocumented
122 102 my $class = shift;
123  
124 0 ▶ if( @_ ) { $STDOUT = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 102 102
125 102 return $STDOUT;
126 }
127  
128 sub write_to_file
129 102 ▶{
Subroutine write_to_file: called CC=2 SCAR=7.6
Pod undocumented
130 102 my $class = shift;
131  
132 0 ▶ if( @_ ) { $FILE = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 102 102
133 102 return $FILE;
134 }
135  
136 sub memory_log_size
137 102 ▶{
Subroutine memory_log_size: called CC=2 SCAR=7.6
Pod undocumented
138 102 my $class = shift;
139  
140 0 ▶ if( @_ ) { $MEM_LOG_SIZE = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 102 102
141 102 return $MEM_LOG_SIZE;
142 }
143  
144 sub memory_log_charge
145 0 ▶{
Subroutine memory_log_charge: not called CC=1 SCAR=6.9
Pod undocumented
146 0 return scalar @MEM_LOG;
147 }
148  
149 sub memory_log
150 0 ▶{
Subroutine memory_log: not called CC=1 SCAR=6.9
Pod undocumented
151 0 my $class = shift;
152 0 my $index;
153  
154 0 return $MEM_LOG[$index];
155 }
156  
157 sub _push_to_memory_log
158 102 ▶{
Subroutine _push_to_memory_log: called CC=3 SCAR=16.0
159 102 my $class = shift;
160 102 my $log = shift;
161  
162 102 ▶ if( $class->memory_log_size )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->memory_log_size) 0 102 102
163 {
164 0 ▶ if( $class->memory_log_charge >= $class->memory_log_size )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->memory_log_charge >= $class->memory_log_size) 0 0 0
165 {
166 0 shift @MEM_LOG;
167 }
168 0 push @MEM_LOG, $log;
169 }
170 }
171  
172 4 1;
« ORM/Filter/Group.pm ↑ Summary ORM/Error.pm »