| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
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 |
|
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
|
|
|
|
|
|
|
$VERSION=0.8; |
|
32
|
|
|
|
|
|
|
|
|
33
|
4
|
|
|
4
|
|
33
|
use ORM::Date; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
3612
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $STDERR; |
|
36
|
|
|
|
|
|
|
my $STDOUT; |
|
37
|
|
|
|
|
|
|
my $FILE; |
|
38
|
|
|
|
|
|
|
my $MEM_LOG_SIZE = 0; |
|
39
|
|
|
|
|
|
|
my @MEM_LOG; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
## |
|
42
|
|
|
|
|
|
|
## CONSTRUCTOR |
|
43
|
|
|
|
|
|
|
## |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new |
|
46
|
|
|
|
|
|
|
{ |
|
47
|
102
|
|
|
102
|
0
|
332
|
my $class = shift; |
|
48
|
102
|
|
|
|
|
1998
|
my %arg = @_; |
|
49
|
102
|
|
|
|
|
191
|
my $self; |
|
50
|
|
|
|
|
|
|
my $caller; |
|
51
|
|
|
|
|
|
|
|
|
52
|
102
|
|
|
|
|
1439
|
for( my $i=1; ; $i++ ) |
|
53
|
|
|
|
|
|
|
{ |
|
54
|
389
|
|
|
|
|
2065
|
$caller = (caller $i )[3]; |
|
55
|
389
|
100
|
100
|
|
|
2995
|
last if( ! defined $caller || ( substr $caller, 0, 9 ) ne 'ORM::Db::' ); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
102
|
|
|
|
|
341
|
$self->{sql} = $arg{sql}; |
|
59
|
102
|
|
|
|
|
250
|
$self->{error} = $arg{error}; |
|
60
|
102
|
|
|
|
|
833
|
$self->{date} = ORM::Datetime->current; |
|
61
|
102
|
|
|
|
|
1322
|
$self->{caller} = $caller; |
|
62
|
|
|
|
|
|
|
|
|
63
|
102
|
|
|
|
|
315
|
bless $self, $class; |
|
64
|
|
|
|
|
|
|
|
|
65
|
102
|
|
|
|
|
477
|
$class->_push_to_memory_log( $self ); |
|
66
|
|
|
|
|
|
|
|
|
67
|
102
|
50
|
|
|
|
388
|
if( $class->write_to_stderr ) |
|
68
|
|
|
|
|
|
|
{ |
|
69
|
0
|
|
|
|
|
0
|
print STDERR $self->text; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
102
|
50
|
|
|
|
4895
|
if( $class->write_to_stdout ) |
|
73
|
|
|
|
|
|
|
{ |
|
74
|
0
|
|
|
|
|
0
|
print $self->text; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
102
|
50
|
|
|
|
334
|
if( $class->write_to_file ) |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
0
|
|
|
|
|
0
|
$class->write_to_file->print( $self->text ); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
102
|
|
|
|
|
859
|
return $self; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
## |
|
86
|
|
|
|
|
|
|
## OBJECT PROPERTIES |
|
87
|
|
|
|
|
|
|
## |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
0
|
0
|
sub sql { $_[0]->{sql}; } |
|
90
|
0
|
|
|
0
|
0
|
0
|
sub error { $_[0]->{error}; } |
|
91
|
0
|
|
|
0
|
0
|
0
|
sub date { $_[0]->{date}; } |
|
92
|
0
|
|
|
0
|
0
|
0
|
sub caller { $_[0]->{caller}; } |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub text |
|
95
|
|
|
|
|
|
|
{ |
|
96
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
97
|
0
|
|
|
|
|
0
|
my $str; |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
0
|
$str .= "--------------------------\n"; |
|
100
|
0
|
0
|
|
|
|
0
|
$str .= '['.$self->date->datetime_str.']: '.$self->caller.': '.( $self->error ? 'FAILED' : 'Success' )."\n"; |
|
101
|
0
|
|
|
|
|
0
|
$str .= $self->sql . "\n"; |
|
102
|
0
|
0
|
|
|
|
0
|
$str .= 'ERROR: ' . $self->error if( $self->error ); |
|
103
|
0
|
|
|
|
|
0
|
$str .= "\n"; |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
0
|
return $str; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
## |
|
109
|
|
|
|
|
|
|
## CLASS METHODS |
|
110
|
|
|
|
|
|
|
## |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub write_to_stderr |
|
113
|
|
|
|
|
|
|
{ |
|
114
|
102
|
|
|
102
|
0
|
206
|
my $class = shift; |
|
115
|
|
|
|
|
|
|
|
|
116
|
102
|
50
|
|
|
|
299
|
if( @_ ) { $STDERR = shift; } |
|
|
0
|
|
|
|
|
0
|
|
|
117
|
102
|
|
|
|
|
413
|
return $STDERR; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub write_to_stdout |
|
121
|
|
|
|
|
|
|
{ |
|
122
|
102
|
|
|
102
|
0
|
189
|
my $class = shift; |
|
123
|
|
|
|
|
|
|
|
|
124
|
102
|
50
|
|
|
|
391
|
if( @_ ) { $STDOUT = shift; } |
|
|
0
|
|
|
|
|
0
|
|
|
125
|
102
|
|
|
|
|
303
|
return $STDOUT; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub write_to_file |
|
129
|
|
|
|
|
|
|
{ |
|
130
|
102
|
|
|
102
|
0
|
187
|
my $class = shift; |
|
131
|
|
|
|
|
|
|
|
|
132
|
102
|
50
|
|
|
|
250
|
if( @_ ) { $FILE = shift; } |
|
|
0
|
|
|
|
|
0
|
|
|
133
|
102
|
|
|
|
|
396
|
return $FILE; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub memory_log_size |
|
137
|
|
|
|
|
|
|
{ |
|
138
|
102
|
|
|
102
|
0
|
174
|
my $class = shift; |
|
139
|
|
|
|
|
|
|
|
|
140
|
102
|
50
|
|
|
|
346
|
if( @_ ) { $MEM_LOG_SIZE = shift; } |
|
|
0
|
|
|
|
|
0
|
|
|
141
|
102
|
|
|
|
|
400
|
return $MEM_LOG_SIZE; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub memory_log_charge |
|
145
|
|
|
|
|
|
|
{ |
|
146
|
0
|
|
|
0
|
0
|
0
|
return scalar @MEM_LOG; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub memory_log |
|
150
|
|
|
|
|
|
|
{ |
|
151
|
0
|
|
|
0
|
0
|
0
|
my $class = shift; |
|
152
|
0
|
|
|
|
|
0
|
my $index; |
|
153
|
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
0
|
return $MEM_LOG[$index]; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub _push_to_memory_log |
|
158
|
|
|
|
|
|
|
{ |
|
159
|
102
|
|
|
102
|
|
648
|
my $class = shift; |
|
160
|
102
|
|
|
|
|
159
|
my $log = shift; |
|
161
|
|
|
|
|
|
|
|
|
162
|
102
|
50
|
|
|
|
379
|
if( $class->memory_log_size ) |
|
163
|
|
|
|
|
|
|
{ |
|
164
|
0
|
0
|
|
|
|
|
if( $class->memory_log_charge >= $class->memory_log_size ) |
|
165
|
|
|
|
|
|
|
{ |
|
166
|
0
|
|
|
|
|
|
shift @MEM_LOG; |
|
167
|
|
|
|
|
|
|
} |
|
168
|
0
|
|
|
|
|
|
push @MEM_LOG, $log; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |