line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#$Id: Base.pm 338 2008-09-28 13:14:54Z zag $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::WebDAO::Base; |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
38
|
use Data::Dumper; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
300
|
|
6
|
6
|
|
|
6
|
|
31
|
use Carp; |
|
6
|
|
|
|
|
22
|
|
|
6
|
|
|
|
|
11227
|
|
7
|
|
|
|
|
|
|
@HTML::WebDAO::Base::ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
@HTML::WebDAO::Base::EXPORT = qw(attributes sess_attributes); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$DEBUG = 0; # assign 1 to it to see code generated on the fly |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub sess_attributes { |
13
|
0
|
|
|
0
|
0
|
0
|
my ($pkg) = caller; |
14
|
0
|
0
|
0
|
|
|
0
|
shift if $_[0] =~ /\:\:/ or $_[0] eq $pkg; |
15
|
0
|
|
|
|
|
0
|
croak "Error: attributes() invoked multiple times" |
16
|
0
|
0
|
|
|
|
0
|
if scalar @{"${pkg}::_SESS_ATTRIBUTES_"}; |
17
|
0
|
|
|
|
|
0
|
@{"${pkg}::_SESS_ATTRIBUTES_"} = @_;#grep { !/^_+/ } @_; |
|
0
|
|
|
|
|
0
|
|
18
|
0
|
|
|
|
|
0
|
my $code = ""; |
19
|
0
|
0
|
|
|
|
0
|
print STDERR "Creating methods for $pkg\n" if $DEBUG; |
20
|
0
|
|
|
|
|
0
|
foreach my $attr (@_) { |
21
|
0
|
0
|
|
|
|
0
|
print STDERR " defining method $attr\n" if $DEBUG; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# If the accessor is already present, give a warning |
24
|
0
|
0
|
|
|
|
0
|
if ( UNIVERSAL::can( $pkg, "$attr" ) ) { |
25
|
0
|
|
|
|
|
0
|
carp "$pkg already has method: $attr"; |
26
|
0
|
|
|
|
|
0
|
next; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# $code .= (UNIVERSAL::can($pkg,"__define_accessor")) ? __define_accessor ($pkg, $attr):_define_accessor ($pkg, $attr); |
30
|
0
|
|
|
|
|
0
|
$code .= _define_accessor( $pkg, $attr ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# $code .= _define_constructor($pkg); |
34
|
0
|
|
|
|
|
0
|
eval $code; |
35
|
0
|
0
|
|
|
|
0
|
if ($@) { |
36
|
0
|
|
|
|
|
0
|
die "ERROR defining and attributes for '$pkg':" |
37
|
|
|
|
|
|
|
. "\n\t$@\n" |
38
|
|
|
|
|
|
|
. "-----------------------------------------------------" |
39
|
|
|
|
|
|
|
. $code; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub attributes { |
46
|
0
|
|
|
0
|
0
|
0
|
my ($pkg) = caller; |
47
|
0
|
0
|
0
|
|
|
0
|
shift if $_[0] =~ /\:\:/ or $_[0] eq $pkg; |
48
|
0
|
|
|
|
|
0
|
my $code = ""; |
49
|
0
|
|
|
|
|
0
|
foreach my $attr (@_) { |
50
|
0
|
0
|
|
|
|
0
|
print STDERR " defining method $attr\n" if $DEBUG; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# If the accessor is already present, give a warning |
53
|
0
|
0
|
|
|
|
0
|
if ( UNIVERSAL::can( $pkg, "$attr" ) ) { |
54
|
0
|
|
|
|
|
0
|
carp "$pkg already has rtl method: $attr"; |
55
|
0
|
|
|
|
|
0
|
next; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
0
|
$code .= _define_accessor( $pkg, $attr ); |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
0
|
eval $code; |
60
|
0
|
0
|
|
|
|
0
|
if ($@) { |
61
|
0
|
|
|
|
|
0
|
die "ERROR defining rtl_attributes for '$pkg':" |
62
|
|
|
|
|
|
|
. "\n\t$@\n" |
63
|
|
|
|
|
|
|
. "-----------------------------------------------------" |
64
|
|
|
|
|
|
|
. $code; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _define_accessor { |
70
|
0
|
|
|
0
|
|
0
|
my ( $pkg, $attr ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# qq makes this block behave like a double-quoted string |
73
|
0
|
|
|
|
|
0
|
my $code = qq{ |
74
|
|
|
|
|
|
|
package $pkg; |
75
|
|
|
|
|
|
|
sub $attr { # Accessor ... |
76
|
|
|
|
|
|
|
my \$self=shift; |
77
|
|
|
|
|
|
|
\@_ ? \$self->set_attribute("$attr",shift):\$self->get_attribute("$attr"); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
}; |
80
|
0
|
|
|
|
|
0
|
$code; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _define_constructor { |
84
|
0
|
|
|
0
|
|
0
|
my $pkg = shift; |
85
|
0
|
|
|
|
|
0
|
my $code = qq { |
86
|
|
|
|
|
|
|
package $pkg; |
87
|
|
|
|
|
|
|
sub new { |
88
|
|
|
|
|
|
|
my \$class =shift; |
89
|
|
|
|
|
|
|
my \$self={}; |
90
|
|
|
|
|
|
|
my \$stat; |
91
|
|
|
|
|
|
|
bless (\$self,\$class); |
92
|
|
|
|
|
|
|
return (\$stat=\$self->_init(\@_)) ? \$self: \$stat; |
93
|
|
|
|
|
|
|
# return \$self if (\$self->_init(\@_)); |
94
|
|
|
|
|
|
|
# return (\$stat=\$self->Error) ? \$stat : "Error initialize"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
}; |
97
|
0
|
|
|
|
|
0
|
$code; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub get_attribute_names { |
101
|
0
|
|
|
0
|
0
|
0
|
my $pkg = shift; |
102
|
0
|
0
|
|
|
|
0
|
$pkg = ref($pkg) if ref($pkg); |
103
|
0
|
|
|
|
|
0
|
my @result = @{"${pkg}::_SESS_ATTRIBUTES_"}; |
|
0
|
|
|
|
|
0
|
|
104
|
0
|
0
|
|
|
|
0
|
if ( defined( @{"${pkg}::ISA"} ) ) { |
|
0
|
|
|
|
|
0
|
|
105
|
0
|
|
|
|
|
0
|
foreach my $base_pkg ( @{"${pkg}::ISA"} ) { |
|
0
|
|
|
|
|
0
|
|
106
|
0
|
|
|
|
|
0
|
push( @result, get_attribute_names($base_pkg) ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
0
|
@result; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub set_attribute { |
113
|
0
|
|
|
0
|
0
|
0
|
my ( $obj, $attr_name, $attr_value ) = @_; |
114
|
0
|
|
|
|
|
0
|
$obj->{"Var"}->{$attr_name} = $attr_value; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# |
118
|
|
|
|
|
|
|
sub get_attribute { |
119
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $attr_name ) = @_; |
120
|
0
|
|
|
|
|
0
|
return $self->{"Var"}->{$attr_name}; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# $obj->set_attributes (name => 'John', age => 23); |
124
|
|
|
|
|
|
|
# Or, $obj->set_attributes (['name', 'age'], ['John', 23]); |
125
|
|
|
|
|
|
|
sub set_attributes { |
126
|
0
|
|
|
0
|
0
|
0
|
my $obj = shift; |
127
|
0
|
|
|
|
|
0
|
my $attr_name; |
128
|
0
|
0
|
|
|
|
0
|
if ( ref( $_[0] ) ) { |
129
|
0
|
|
|
|
|
0
|
my ( $attr_name_list, $attr_value_list ) = @_; |
130
|
0
|
|
|
|
|
0
|
my $i = 0; |
131
|
0
|
|
|
|
|
0
|
foreach $attr_name (@$attr_name_list) { |
132
|
0
|
|
|
|
|
0
|
$obj->$attr_name( $attr_value_list->[ $i++ ] ); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
else { |
136
|
0
|
|
|
|
|
0
|
my ( $attr_name, $attr_value ); |
137
|
0
|
|
|
|
|
0
|
while (@_) { |
138
|
0
|
|
|
|
|
0
|
$attr_name = shift; |
139
|
0
|
|
|
|
|
0
|
$attr_value = shift; |
140
|
0
|
|
|
|
|
0
|
$obj->$attr_name($attr_value); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# @attrs = $obj->get_attributes (qw(name age)); |
146
|
|
|
|
|
|
|
sub get_attributes { |
147
|
0
|
|
|
0
|
0
|
0
|
my $obj = shift; |
148
|
0
|
|
|
|
|
0
|
my (@retval); |
149
|
0
|
|
|
|
|
0
|
map { $obj->$_() } @_; |
|
0
|
|
|
|
|
0
|
|
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub new { |
153
|
3
|
|
|
3
|
0
|
73
|
my $class = shift; |
154
|
3
|
|
|
|
|
9
|
my $self = {}; |
155
|
3
|
|
|
|
|
8
|
my $stat; |
156
|
3
|
|
|
|
|
10
|
bless( $self, $class ); |
157
|
3
|
50
|
|
|
|
25
|
return ( $stat = $self->_init(@_) ) ? $self : $stat; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub _init { |
161
|
0
|
|
|
0
|
|
|
my $self = shift; |
162
|
0
|
|
|
|
|
|
return 1; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
#put message into syslog |
166
|
|
|
|
|
|
|
sub _deprecated { |
167
|
0
|
|
|
0
|
|
|
my $self = shift; |
168
|
0
|
|
|
|
|
|
my $new_method = shift; |
169
|
0
|
|
|
|
|
|
my ( $old_method, $called_from_str, $called_from_method ) = |
170
|
|
|
|
|
|
|
( ( caller(1) )[3], ( caller(1) )[2], ( caller(2) )[3] ); |
171
|
0
|
|
|
|
|
|
$self->_log3( |
172
|
|
|
|
|
|
|
"called deprecated method $old_method from $called_from_method at line $called_from_str. Use method $new_method instead." |
173
|
|
|
|
|
|
|
); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub logmsgs { |
177
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
178
|
0
|
|
|
|
|
|
$self->_deprecated("_log1,_log2"); |
179
|
0
|
|
|
|
|
|
$self->_log1(@_); |
180
|
|
|
|
|
|
|
} |
181
|
0
|
|
|
0
|
|
|
sub _log1 { my $self = shift; $self->_log( level => 1, par => \@_ ) } |
|
0
|
|
|
|
|
|
|
182
|
0
|
|
|
0
|
|
|
sub _log2 { my $self = shift; $self->_log( level => 2, par => \@_ ) } |
|
0
|
|
|
|
|
|
|
183
|
0
|
|
|
0
|
|
|
sub _log3 { my $self = shift; $self->_log( level => 3, par => \@_ ) } |
|
0
|
|
|
|
|
|
|
184
|
0
|
|
|
0
|
|
|
sub _log4 { my $self = shift; $self->_log( level => 4, par => \@_ ) } |
|
0
|
|
|
|
|
|
|
185
|
0
|
|
|
0
|
|
|
sub _log5 { my $self = shift; $self->_log( level => 5, par => \@_ ) } |
|
0
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub _log { |
188
|
0
|
|
|
0
|
|
|
my $self = shift; |
189
|
0
|
|
|
|
|
|
my %args = @_; |
190
|
0
|
|
|
|
|
|
my ($mod_sub,$str) = (caller(2))[3,2]; |
191
|
0
|
|
|
|
|
|
($str) = (caller(1))[2]; |
192
|
0
|
|
|
|
|
|
print STDERR "$$ [$args{level}] $mod_sub:$str @{$args{par}} \n"; |
|
0
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub LOG { |
196
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
197
|
0
|
|
|
|
|
|
$self->_deprecated("_log1,_log2"); |
198
|
0
|
|
|
|
|
|
return $self->logmsgs(@_); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
1; |