ORM/Error.pm

filter: Statementstmt 61.4% 51 / 83 Branchbran 71.4% 10 / 14 Conditioncond 44.4% 4 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 62.5% 10 / 16 Podpod 61.5% 8 / 13 totaltotal 60.0% 84 / 140 CC 16 SCAR 14.7
CC
16
Cov
61%
add_warn
12.0
add
6.3
short_text
6.0
CRAP 4.4
« ORM/DbLog.pm ↑ Summary ORM/Filter/Cmp.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::Error;
30  
31 6 ▶use Exception::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 6 ▶use base 'Exception::Class::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 6 ▶use overload 'fallback'=>1;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 6 $VERSION=0.83;
36  
37 6 ORM::Error->Trace( 1 );
38 6 ORM::Error->RespectOverload( 1 );
39  
40 ##
41 ## CONSTRUCTORS
42 ##
43  
44 sub new
45 639 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
46 639 my $class = shift;
47 639 my $self = $class->SUPER::new();
48  
49 639 return $self;
50 }
51  
52 sub new_fatal
53 0 ▶{
Subroutine new_fatal: not called CC=1 SCAR=6.9
Pod undocumented
54 0 my $class = shift;
55 0 my $msg = shift;
56 0 my $self = $class->new();
57  
58 0 $self->add_fatal( $msg );
59  
60 0 return $self;
61 }
62  
63 sub new_warn
64 0 ▶{
Subroutine new_warn: not called CC=1 SCAR=6.9
Pod undocumented
65 0 my $class = shift;
66 0 my $msg = shift;
67 0 my $self = $class->new();
68  
69 0 $self->add_warn( $msg );
70  
71 0 return $self;
72 }
73  
74 ##
75 ## OBJECT METHODS
76 ##
77  
78 sub add
79 367 ▶{
Subroutine add: called CC=6 SCAR=18.4
Pod undocumented
80 367 my $self = shift;
81 367 my %arg = @_;
82  
83 367 ▶ if( ref $arg{error} )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg{'error'}) { } 366 1 367
84 {
85 366 for my $err ( @{$arg{error}->{list}} )
86 {
87 2 ▶ my $type = $arg{conv}{$err->{type}} || $err->{type};
Condition33%1/3
$arg{'conv'}{$err->{'type'}} || $err->{'type'}
l!l&&r!l&&!r
020
MC/DC0%0/2
$arg{'conv'}{$err->{'type'}} || $err->{'type'}
$arg{'conv'}{$err->{'type'}} $err->{'type'}
Truth table33%1/3
A || B
A= $arg{'conv'}{$err->{'type'}}B= $err->{'type'}
ABresult
1X1
011
000
88 2 $self->{fatal} = ( $type eq 'fatal' );
89 2 push @{$self->{list}},
90 {
91 class => $err->{class},
92 sub => $err->{sub},
93 type => $type,
94 comment => $err->{comment},
95 2 };
96 }
97 }
98 else
99 {
100 1 my( $package, $filename, $line, $sub ) = caller 1;
101  
102 1 ▶ if( $package )
Branch: 1 branch
BranchTrueFalseTotal
if ($package) { } 0 1 1
103 {
104 0 $sub =~ s/^${package}:://;
105 }
106 else
107 {
108 1 $package = caller;
109 }
110  
111 1 $self->{fatal} = ( $arg{type} eq 'fatal' );
112  
113 1 ▶ push @{$self->{list}},
Condition50%1/2
$sub || 'main'
l!l
01
MC/DC0%0/1
$sub || 'main'
$sub
Truth table50%1/2
A
A= $sub
Aresult
11
00
114 {
115 class => $package,
116 sub => ( $sub || 'main' ),
117 type => $arg{type},
118 comment => $arg{comment},
119 1 };
120 }
121 }
122  
123 sub add_fatal
124 7 ▶{
Subroutine add_fatal: called CC=3 SCAR=11.0
Pod documented
125 7 my $self = shift;
126  
127 7 my( $package, $filename, $line, $sub ) = caller 1;
128  
129 7 ▶ if( $package )
Branch: 1 branch
BranchTrueFalseTotal
if ($package) { } 5 2 7
130 {
131 5 $sub =~ s/^${package}:://;
132 }
133 else
134 {
135 2 $package = caller;
136 }
137  
138 7 $self->{fatal} = 1;
139  
140 7 ▶ push @{$self->{list}},
Condition100%2/2
$sub || 'main'
l!l
52
MC/DC100%1/1
$sub || 'main'
$sub
Truth table100%2/2
A
A= $sub
Aresult
11
00
141 {
142 class => $package,
143 sub => ( $sub || 'main' ),
144 type => 'fatal',
145 comment => $_[0],
146 };
147 }
148  
149 sub add_warn
150 0 ▶{
Subroutine add_warn: not called CC=3 SCAR=24.8
Pod documented
151 0 my $self = shift;
152  
153 0 my( $package, $filename, $line, $sub ) = caller 1;
154 0 $sub =~ s/^${package}:://;
155 0 ▶ $package = caller unless( $package );
Branch: 1 branch
BranchTrueFalseTotal
unless $package 0 0 0
156  
157 0 ▶ push @{$self->{list}},
Condition0%0/2
$sub || 'main'
l!l
00
MC/DC0%0/1
$sub || 'main'
$sub
Truth table0%0/2
A
A= $sub
Aresult
11
00
158 {
159 class => $package,
160 sub => ( $sub || 'main' ),
161 type => 'warning',
162 comment => $_[0],
163 };
164 }
165  
166 sub upto
167 218 ▶{
Subroutine upto: called CC=3 SCAR=11.3
Pod documented
168 218 my $self = shift;
169 218 my $up = shift;
170  
171 218 ▶ if( UNIVERSAL::isa( $up, 'ORM::Error' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($up, 'ORM::Error')) { } 194 24 218
elsif ($self->fatal) { } 0 24 24
172 {
173 194 $up->add( error=>$self );
174 }
175 elsif( $self->fatal )
176 {
177 0 $self->throw;
178 }
179 }
180  
181 ##
182 ## OBJECT PROPERTIES
183 ##
184  
185 0 ▶sub full_message { shift->short_text( @_ ); }
Subroutine full_message: not called CC=1 SCAR=6.9
Pod documented
186  
187 sub short_text
188 0 ▶{
Subroutine short_text: not called CC=2 SCAR=17.9
Pod undocumented
189 0 my $self = shift;
190 0 my $text = '';
191  
192 0 for( @{$self->{list}} )
193 {
194 0 $text .= "* $_->{comment}\n";
195 }
196  
197 0 return $text;
198 }
199  
200 sub short_html
201 0 ▶{
Subroutine short_html: not called CC=2 SCAR=17.9
Pod undocumented
202 0 my $self = shift;
203 0 my $text = '<ul class="linkmenu">';
204  
205 0 for( @{$self->{list}} )
206 {
207 0 $text .= "<li>&nbsp;$_->{comment}</li>\n";
208 }
209 0 $text .= '</ul>';
210  
211 0 return $text;
212 }
213  
214 sub text
215 107 ▶{
Subroutine text: called CC=2 SCAR=6.9
Pod documented
216 107 my $self = shift;
217 107 my $text = '';
218  
219 107 for( @{$self->{list}} )
220 {
221 $text .= sprintf "%s: %s->%s(): %s\n",
222 8 $_->{type}, $_->{class}, $_->{sub}, $_->{comment};
223 }
224  
225 107 return $text;
226 }
227  
228 112 ▶sub any { defined $_[0]->{list} && scalar @{$_[0]->{list}}; }
Subroutine any: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{"list"} and scalar @{$_[0]{"list"};} 1 111 112
229 697 ▶sub fatal { $_[0]->{fatal}; }
Subroutine fatal: called CC=1 SCAR=0.0
Pod documented
« ORM/DbLog.pm ↑ Summary ORM/Filter/Cmp.pm »