blib/lib/WebDAO/Element.pm

filter: Statementstmt 33.3% 34 / 102 Branchbran 3.3% 1 / 30 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 37.5% 9 / 24 Podpod 33.3% 2 / 6 totaltotal 27.0% 46 / 170 CC 18 SCAR 26.4
CC
18
Cov
26%
url_method
42.0
__any_path
30.0
_set_path2me
14.4
CRAP 14.0
« blib/lib/WebDAO/Util.pm ↑ Summary blib/lib/WebDAO/Config.pm »
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 5 our $VERSION = '0.01';
16  
17 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use WebDAO::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use base qw/ WebDAO::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 5 __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 ▶ my $self = shift;
Subroutine _init: called CC=1 SCAR=0.0
42 1 $self->_sysinit( \@_ ); #For system internal inherites
43 1 $self->init(@_); # if (@_);
44 1 return 1;
45 }
46  
47  
48 ######## EVENTS ######
49  
50 sub __register_event__ {
51 0 ▶ my $self = shift;
Subroutine __register_event__: not called CC=1 SCAR=6.9
52 0 my $ref_eng = $self->_root_;
53 0 $ref_eng->__register_event__( $self, @_ );
54 }
55  
56 sub __send_event__ {
57 0 ▶ my $self = shift;
Subroutine __send_event__: not called CC=3 SCAR=24.8
58 0 ▶ my $parent = $self->__parent || $self->_root_;
Condition0%0/3
$self->__parent || $self->_root_
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->__parent || $self->_root_
$self->__parent $self->_root_
Truth table0%0/3
A || B
A= $self->__parentB= $self->_root_
ABresult
1X1
011
000
59 $self->_log1( "Not def parent $self name:"
60 . ( $self->__my_name )
61 . Dumper( \@_ )
62 0 ▶ . Dumper( [ map { [ caller($_) ] } ( 1 .. 10 ) ] ) )
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
63 unless $parent;
64 0 $parent->__send_event__(@_);
65 }
66  
67 #
68 sub _sysinit {
69 1 ▶ my $self = shift;
Subroutine _sysinit: called CC=1 SCAR=0.0
70  
71 #get init hash reference
72 1 my $ref_init_hash = shift( @{ $_[0] } );
73  
74 #_engine - reference to engine
75 1 $self->__engine( $ref_init_hash->{ref_engine} );
76  
77 #_my_name - name of this object
78 1 $self->__my_name( $ref_init_hash->{name_obj} );
79 }
80  
81 ▶sub init {
Subroutine init: not called CC=1 SCAR=0.0
Pod undocumented
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 ▶ return [];
Subroutine _get_childs_: not called CC=1 SCAR=6.9
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 ▶ my $self = shift;
Subroutine __any_path: not called CC=5 SCAR=34.0
108 0 my $sess = shift;
109 0 my ( $method, @path ) = @_;
110 #first check if Method
111 #Check upper case First letter for method
112 0 ▶ if ( ucfirst($method) ne $method ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ucfirst $method ne $method) 0 0 0
113  
114 #warn "Deny method : $method";
115 0 return undef; #not found
116 }
117  
118 #check if $self have method
119 0 ▶ if ( UNIVERSAL::can( $self, $method ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($self, $method)) 0 0 0
120  
121 #now try call method
122 #Ok have method
123 #check if path have more elements
124 0 my %args = %{ $sess->Params };
125 0 ▶ if (@path) {
Branch: 1 branch
BranchTrueFalseTotal
if (@path) 0 0 0
126  
127 #add special variable
128 0 $args{__extra_path__} = \@path;
129 }
130  
131 #call method (only one param may be return)
132 0 my ($res, @path1) = $self->$method(%args);
133 0 ▶ if ( scalar(@path1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @path1) 0 0 0
134 #method may return extra path
135 0 return $res, \@path1;
136 }
137 0 return $res, \@path;
138 }
139 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 ▶ my $self = shift;
Subroutine _traverse_: not called CC=3 SCAR=24.8
151 0 my $sess = shift;
152  
153 #if empty path return $self
154 0 ▶ unless ( scalar(@_) ) { return ( $self, $self ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @_) 0 0 0
155 0 my ( $next_name, @path ) = @_;
156  
157 #try get objects by special methods
158 0 my ( $res, $last_path ) = $self->__any_path( $sess, $next_name, @path );
159 0 ▶ return ( $self, undef ) unless defined $res; #break search
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
160 0 return ( $self, $res );
161 }
162  
163 sub __get_self_refs {
164 0 ▶ return $_[0];
Subroutine __get_self_refs: not called CC=1 SCAR=6.9
165 }
166  
167 sub _set_parent {
168 1 ▶ my ( $self, $parent ) = @_;
Subroutine _set_parent: called CC=1 SCAR=0.0
169 1 $self->__parent($parent);
170 1 $self->_set_path2me();
171 }
172  
173 sub _set_path2me {
174 1 ▶ my $self = shift;
Subroutine _set_path2me: called CC=5 SCAR=26.7
175 1 my $parent = $self->__parent;
176 1 ▶ if ( $self != $parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self != $parent) { } 0 1 1
177 0 ▶ ( my $parents_path = $parent->__path2me ) ||= "";
Condition0%0/2
(my $parents_path = $parent->__path2me) ||= ""
l!l
00
MC/DC0%0/1
(my $parents_path = $parent->__path2me) ||= ""
(my $parents_path = $parent->__path2me)
Truth table0%0/2
A
A= (my $parents_path = $parent->__path2me)
Aresult
11
00
178 0 my $extr = $parent->__extra_path;
179 0 ▶ $extr = [] unless defined $extr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $extr 0 0 0
180 0 ▶ $extr = [$extr] unless ( ref($extr) eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $extr eq "ARRAY" 0 0 0
181 0 my $my_path = join "/", $parents_path, @$extr, $self->__my_name;
182 0 $self->__path2me($my_path);
183 }
184 else {
185 1 $self->__path2me('');
186 }
187 }
188  
189 #deprecated -> $obj->__my_name
190 sub _obj_name {
191 0 ▶ return $_[0]->__my_name;
Subroutine _obj_name: not called CC=1 SCAR=6.9
192 }
193  
194  
195 #deprecated -> self->_root_
196 sub getEngine {
197 0 ▶ my $self = shift;
Subroutine getEngine: not called CC=1 SCAR=6.9
Pod undocumented
198 0 return $self->__engine;
199 }
200  
201 0 ▶sub _root_ { return $_[0]->__engine }
Subroutine _root_: not called CC=1 SCAR=6.9
202  
203 0 ▶sub fetch { undef } #return undef
Subroutine fetch: not called CC=1 SCAR=6.9
Pod undocumented
204  
205 sub _destroy {
206 0 ▶ my $self = shift;
Subroutine _destroy: not called CC=1 SCAR=6.9
207 0 $self->__parent(undef);
208 0 $self->__engine(undef);
209 }
210  
211 sub url_method {
212 0 ▶ my $self = shift;
Subroutine url_method: not called CC=6 SCAR=37.4
Pod undocumented
213 0 my $method = shift;
214 0 my @upath = ();
215 0 ▶ push @upath, $self->__path2me if $self->__path2me;
Branch: 1 branch
BranchTrueFalseTotal
if $self->__path2me 0 0 0
216 0 ▶ push @upath, $method if defined $method;
Branch: 1 branch
BranchTrueFalseTotal
if defined $method 0 0 0
217 0 my $sess = $self->_root_->_session;
218 0 ▶ if ( $sess->set_absolute_url() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sess->set_absolute_url) 0 0 0
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 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
227 0 my %args = @_;
228 0 my @pars;
229 0 ▶ while ( my ( $key, $val ) = each %args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 0 0
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 ▶ my $self = shift;
Subroutine response: not called CC=1 SCAR=6.9
Pod documented
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 ▶ return $_[0]->response->get_request();
Subroutine request: not called CC=1 SCAR=6.9
Pod documented
260 }
261  
262  
263 5 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  
« blib/lib/WebDAO/Util.pm ↑ Summary blib/lib/WebDAO/Config.pm »