| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebDAO::Element; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
WebDAO::Element - Base class for simple object |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
WebDAO::Element - Base class for simple object |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
6
|
|
|
6
|
|
1419
|
use Data::Dumper; |
|
|
6
|
|
|
|
|
18675
|
|
|
|
6
|
|
|
|
|
311
|
|
|
18
|
6
|
|
|
6
|
|
789
|
use WebDAO::Base; |
|
|
6
|
|
|
|
|
15
|
|
|
|
6
|
|
|
|
|
366
|
|
|
19
|
6
|
|
|
6
|
|
37
|
use base qw/ WebDAO::Base/; |
|
|
6
|
|
|
|
|
12
|
|
|
|
6
|
|
|
|
|
473
|
|
|
20
|
6
|
|
|
6
|
|
35
|
use warnings; |
|
|
6
|
|
|
|
|
18
|
|
|
|
6
|
|
|
|
|
169
|
|
|
21
|
6
|
|
|
6
|
|
46
|
use strict 'vars'; |
|
|
6
|
|
|
|
|
19
|
|
|
|
6
|
|
|
|
|
5270
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
__PACKAGE__->mk_attr( |
|
24
|
|
|
|
|
|
|
__my_name => undef, |
|
25
|
|
|
|
|
|
|
__parent => undef, |
|
26
|
|
|
|
|
|
|
__path2me => undef, |
|
27
|
|
|
|
|
|
|
__engine => undef, |
|
28
|
|
|
|
|
|
|
__extra_path => undef |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 NAME |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
WebDAO::Element - WebDAO::Element. |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _init { |
|
41
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
|
42
|
1
|
|
|
|
|
54
|
$self->_sysinit( \@_ ); #For system internal inherites |
|
43
|
1
|
|
|
|
|
6
|
$self->init(@_); # if (@_); |
|
44
|
1
|
|
|
|
|
5
|
return 1; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
######## EVENTS ###### |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub __register_event__ { |
|
51
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
52
|
0
|
|
|
|
|
0
|
my $ref_eng = $self->_root_; |
|
53
|
0
|
|
|
|
|
0
|
$ref_eng->__register_event__( $self, @_ ); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub __send_event__ { |
|
57
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
58
|
0
|
|
0
|
|
|
0
|
my $parent = $self->__parent || $self->_root_; |
|
59
|
|
|
|
|
|
|
$self->_log1( "Not def parent $self name:" |
|
60
|
|
|
|
|
|
|
. ( $self->__my_name ) |
|
61
|
|
|
|
|
|
|
. Dumper( \@_ ) |
|
62
|
0
|
0
|
|
|
|
0
|
. Dumper( [ map { [ caller($_) ] } ( 1 .. 10 ) ] ) ) |
|
|
0
|
|
|
|
|
0
|
|
|
63
|
|
|
|
|
|
|
unless $parent; |
|
64
|
0
|
|
|
|
|
0
|
$parent->__send_event__(@_); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# |
|
68
|
|
|
|
|
|
|
sub _sysinit { |
|
69
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#get init hash reference |
|
72
|
1
|
|
|
|
|
2
|
my $ref_init_hash = shift( @{ $_[0] } ); |
|
|
1
|
|
|
|
|
3
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#_engine - reference to engine |
|
75
|
1
|
|
|
|
|
28
|
$self->__engine( $ref_init_hash->{ref_engine} ); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#_my_name - name of this object |
|
78
|
1
|
|
|
|
|
20
|
$self->__my_name( $ref_init_hash->{name_obj} ); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
0
|
0
|
|
sub init { |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#Public Init metod for modules; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 _get_childs_() |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Return ref to childs array |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
|
92
|
|
|
|
|
|
|
sub _get_childs_ { |
|
93
|
0
|
|
|
0
|
|
0
|
return []; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 __any_path ($session, @path) |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Call for unresolved path. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Return: |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
($resuilt, \@rest_of_the_path) |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub __any_path { |
|
107
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
108
|
0
|
|
|
|
|
0
|
my $sess = shift; |
|
109
|
0
|
|
|
|
|
0
|
my ( $method, @path ) = @_; |
|
110
|
|
|
|
|
|
|
#first check if Method |
|
111
|
|
|
|
|
|
|
#Check upper case First letter for method |
|
112
|
0
|
0
|
|
|
|
0
|
if ( ucfirst($method) ne $method ) { |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#warn "Deny method : $method"; |
|
115
|
0
|
|
|
|
|
0
|
return undef; #not found |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
#check if $self have method |
|
119
|
0
|
0
|
|
|
|
0
|
if ( UNIVERSAL::can( $self, $method ) ) { |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#now try call method |
|
122
|
|
|
|
|
|
|
#Ok have method |
|
123
|
|
|
|
|
|
|
#check if path have more elements |
|
124
|
0
|
|
|
|
|
0
|
my %args = %{ $sess->Params }; |
|
|
0
|
|
|
|
|
0
|
|
|
125
|
0
|
0
|
|
|
|
0
|
if (@path) { |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#add special variable |
|
128
|
0
|
|
|
|
|
0
|
$args{__extra_path__} = \@path; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
#call method (only one param may be return) |
|
132
|
0
|
|
|
|
|
0
|
my ($res, @path1) = $self->$method(%args); |
|
133
|
0
|
0
|
|
|
|
0
|
if ( scalar(@path1) ) { |
|
134
|
|
|
|
|
|
|
#method may return extra path |
|
135
|
0
|
|
|
|
|
0
|
return $res, \@path1; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
0
|
|
|
|
|
0
|
return $res, \@path; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
0
|
|
|
|
|
0
|
undef; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#return |
|
144
|
|
|
|
|
|
|
# undef = not found |
|
145
|
|
|
|
|
|
|
# [ array of object] |
|
146
|
|
|
|
|
|
|
# <$self|| WebDAO::Element> ( ? for isert to parent container ?) |
|
147
|
|
|
|
|
|
|
# "STRING" |
|
148
|
|
|
|
|
|
|
# <WebDAO::Response> |
|
149
|
|
|
|
|
|
|
sub _traverse_ { |
|
150
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
151
|
0
|
|
|
|
|
0
|
my $sess = shift; |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
#if empty path return $self |
|
154
|
0
|
0
|
|
|
|
0
|
unless ( scalar(@_) ) { return ( $self, $self ) } |
|
|
0
|
|
|
|
|
0
|
|
|
155
|
0
|
|
|
|
|
0
|
my ( $next_name, @path ) = @_; |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
#try get objects by special methods |
|
158
|
0
|
|
|
|
|
0
|
my ( $res, $last_path ) = $self->__any_path( $sess, $next_name, @path ); |
|
159
|
0
|
0
|
|
|
|
0
|
return ( $self, undef ) unless defined $res; #break search |
|
160
|
0
|
|
|
|
|
0
|
return ( $self, $res ); |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub __get_self_refs { |
|
164
|
0
|
|
|
0
|
|
0
|
return $_[0]; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub _set_parent { |
|
168
|
1
|
|
|
1
|
|
3
|
my ( $self, $parent ) = @_; |
|
169
|
1
|
|
|
|
|
24
|
$self->__parent($parent); |
|
170
|
1
|
|
|
|
|
7
|
$self->_set_path2me(); |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub _set_path2me { |
|
174
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
|
175
|
1
|
|
|
|
|
15
|
my $parent = $self->__parent; |
|
176
|
1
|
50
|
|
|
|
4
|
if ( $self != $parent ) { |
|
177
|
0
|
|
0
|
|
|
0
|
( my $parents_path = $parent->__path2me ) ||= ""; |
|
178
|
0
|
|
|
|
|
0
|
my $extr = $parent->__extra_path; |
|
179
|
0
|
0
|
|
|
|
0
|
$extr = [] unless defined $extr; |
|
180
|
0
|
0
|
|
|
|
0
|
$extr = [$extr] unless ( ref($extr) eq 'ARRAY' ); |
|
181
|
0
|
|
|
|
|
0
|
my $my_path = join "/", $parents_path, @$extr, $self->__my_name; |
|
182
|
0
|
|
|
|
|
0
|
$self->__path2me($my_path); |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
else { |
|
185
|
1
|
|
|
|
|
18
|
$self->__path2me(''); |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
#deprecated -> $obj->__my_name |
|
190
|
|
|
|
|
|
|
sub _obj_name { |
|
191
|
0
|
|
|
0
|
|
|
return $_[0]->__my_name; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
#deprecated -> self->_root_ |
|
196
|
|
|
|
|
|
|
sub getEngine { |
|
197
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
198
|
0
|
|
|
|
|
|
return $self->__engine; |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
|
|
201
|
0
|
|
|
0
|
|
|
sub _root_ { return $_[0]->__engine } |
|
202
|
|
|
|
|
|
|
|
|
203
|
0
|
|
|
0
|
0
|
|
sub fetch { undef } #return undef |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub _destroy { |
|
206
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
207
|
0
|
|
|
|
|
|
$self->__parent(undef); |
|
208
|
0
|
|
|
|
|
|
$self->__engine(undef); |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub url_method { |
|
212
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
213
|
0
|
|
|
|
|
|
my $method = shift; |
|
214
|
0
|
|
|
|
|
|
my @upath = (); |
|
215
|
0
|
0
|
|
|
|
|
push @upath, $self->__path2me if $self->__path2me; |
|
216
|
0
|
0
|
|
|
|
|
push @upath, $method if defined $method; |
|
217
|
0
|
|
|
|
|
|
my $sess = $self->_root_->_session; |
|
218
|
0
|
0
|
|
|
|
|
if ( $sess->set_absolute_url() ) { |
|
219
|
0
|
|
|
|
|
|
my $root = $sess->Cgi_env->{base_url}; |
|
220
|
0
|
|
|
|
|
|
unshift @upath, $sess->Cgi_env->{base_url}; |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
#hack !!! clear / on begin |
|
223
|
|
|
|
|
|
|
#s{^/}{} for @upath; |
|
224
|
0
|
|
|
|
|
|
my $path = join '/' => @upath; |
|
225
|
0
|
|
|
|
|
|
my $str = ''; |
|
226
|
0
|
0
|
|
|
|
|
if (@_) { |
|
227
|
0
|
|
|
|
|
|
my %args = @_; |
|
228
|
0
|
|
|
|
|
|
my @pars; |
|
229
|
0
|
|
|
|
|
|
while ( my ( $key, $val ) = each %args ) { |
|
230
|
0
|
|
|
|
|
|
push @pars, "$key=$val"; |
|
231
|
|
|
|
|
|
|
} |
|
232
|
0
|
|
|
|
|
|
$str .= "?" . join "&" => @pars; |
|
233
|
|
|
|
|
|
|
} |
|
234
|
0
|
|
|
|
|
|
return $path . $str; |
|
235
|
|
|
|
|
|
|
} |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head2 response |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Return response object |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
return $self->response->error404('Bad name') |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=cut |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub response { |
|
246
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
247
|
0
|
|
|
|
|
|
return $self->_root_->response; |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head2 request |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Return request object |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
$self->request->param('id') |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=cut |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub request { |
|
259
|
0
|
|
|
0
|
1
|
|
return $_[0]->response->get_request(); |
|
260
|
|
|
|
|
|
|
} |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
1; |
|
264
|
|
|
|
|
|
|
__DATA__ |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
http://webdao.sourceforge.net |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head1 AUTHOR |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
Zahatski Aliaksandr, E<lt>zag@cpan.orgE<gt> |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Copyright 2002-2012 by Zahatski Aliaksandr |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
279
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=cut |
|
282
|
|
|
|
|
|
|
|