blib/lib/WebDAO/Base.pm

filter: Statementstmt 64.3% 255 / 396 Branchbran 45.4% 111 / 244 Conditioncond 18.7% 3 / 16 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 69.2% 36 / 52 Podpod 33.3% 3 / 9 totaltotal 56.4% 410 / 726 CC 148 SCAR 19.8
CC
148
Cov
56%
mk_route
42.7
_log
42.0
mk_attr
7.7
CRAP 7.2
« blib/lib/WebDAO/FCGI/ProcManager.pm ↑ Summary blib/lib/WebDAO/Lexer/regclass.pm »
1 package WebDAO::Base;
2 9 our $VERSION = '0.02';
3  
4 =head1 NAME
5  
6 WebDAO::Base - Base class
7  
8 =head1 SYNOPSIS
9  
10 =head1 DESCRIPTION
11  
12 WebDAO::Base - Base class
13  
14 =cut
15  
16 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 9 @WebDAO::Base::ISA = qw(Exporter);
20 9 @WebDAO::Base::EXPORT = qw(mk_attr mk_route _log1 _log2 _log3
21 _log4 _log5 _log6);
22  
23 =head2 mk_attr ( _attr1=>'default value', __attr2=>undef, __attr2=>1)
24  
25 Make accessor for class attribute
26  
27 use WebDAO;
28 mk_attr( _session=>undef, __obj=>undef, __events=>undef);
29  
30  
31 =cut
32  
33 sub mk_attr {
34 41 ▶ my ($pkg) = caller;
Subroutine mk_attr: called CC=6 SCAR=20.4
Pod documented
35 41 ▶ shift if $_[0] =~ /\:\:/ or $_[0] eq $pkg;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /\:\:/ or $_[0] eq $pkg 37 4 41
Condition100%3/3
$_[0] =~ /\:\:/ or $_[0] eq $pkg
l!l&&r!l&&!r
3614
MC/DC100%2/2
$_[0] =~ /\:\:/ or $_[0] eq $pkg
$_[0] =~ /\:\:/ $_[0] eq $pkg
Truth table100%3/3
A or B
A= $_[0] =~ /\:\:/B= $_[0] eq $pkg
ABresult
1X1
011
000
36 41 my %attrs = @_;
37 41 %{"${pkg}::_WEBDAO_ATTRIBUTES_"} = %attrs;
38 41 my $code = "";
39 41 foreach my $attr ( keys %attrs ) {
40  
41 # If the accessor is already present, give a warning
42 172 ▶ if ( UNIVERSAL::can( $pkg, "$attr" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($pkg, "$attr")) 0 172 172
43 0 carp "$pkg already has method: $attr";
44 0 next;
45 }
46 172 $code .= _define_attr_accessor( $pkg, $attr, $attrs{$attr} );
47 }
48 41 ▶ eval $code;
Subroutine Cgi_env: called CC=4 SCAR=15.7
Subroutine Cgi_obj: called CC=4 SCAR=15.7
Subroutine Params: called CC=4 SCAR=15.7
Subroutine U_id: called CC=4 SCAR=15.7
Subroutine __childs: called CC=4 SCAR=15.7
Subroutine __engine: called CC=4 SCAR=15.7
Subroutine __events: called CC=4 SCAR=15.7
Subroutine __extra_path: not called CC=4 SCAR=15.7
Subroutine __fh: called CC=4 SCAR=15.7
Subroutine __my_name: called CC=4 SCAR=15.7
Subroutine __obj: called CC=4 SCAR=15.7
Subroutine __parent: called CC=4 SCAR=15.7
Subroutine __path2me: called CC=4 SCAR=15.7
Subroutine __post_childs: called CC=4 SCAR=15.7
Subroutine __pre_childs: called CC=4 SCAR=15.7
Subroutine _args: not called CC=4 SCAR=15.7
Subroutine _call_backs: called CC=4 SCAR=15.7
Subroutine _cv_obj: called CC=4 SCAR=15.7
Subroutine _forced_want_format: called CC=4 SCAR=15.7
Subroutine _headers: called CC=4 SCAR=15.7
Subroutine _is_absolute_url: not called CC=4 SCAR=15.7
Subroutine _is_empty: not called CC=4 SCAR=15.7
Subroutine _is_file_send: called CC=4 SCAR=15.7
Subroutine _is_flushed: called CC=4 SCAR=15.7
Subroutine _is_headers_printed: called CC=4 SCAR=15.7
Subroutine _is_modal: called CC=4 SCAR=15.7
Subroutine _is_need_close_fh: called CC=4 SCAR=15.7
Subroutine _parsed_cookies: called CC=4 SCAR=15.7
Subroutine _path: called CC=4 SCAR=15.7
Subroutine _raw_html: not called CC=4 SCAR=15.7
Subroutine _response_obj: called CC=4 SCAR=15.7
Subroutine _session: called CC=4 SCAR=15.7
Subroutine status: called CC=4 SCAR=15.7
Subroutine status: called CC=4 SCAR=15.7
Subroutine __conf: called CC=4 SCAR=15.7
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 105 branches
BranchTrueFalseTotal
if (@_) 4 12 16
exists $self->{'Cgi_env'} ? : 0 4 4
unless exists $self->{"Cgi_env"} 0 12 12
if (@_) 4 11 15
exists $self->{'Cgi_obj'} ? : 0 4 4
unless exists $self->{"Cgi_obj"} 0 11 11
if (@_) 7 0 7
exists $self->{'Params'} ? : 3 4 7
unless exists $self->{"Params"} 0 0 0
if (@_) 10 0 10
exists $self->{'U_id'} ? : 6 4 10
unless exists $self->{"U_id"} 0 0 0
if (@_) 1 1 2
exists $self->{'__childs'} ? : 0 1 1
unless exists $self->{"__childs"} 0 1 1
if (@_) 1 0 1
exists $self->{'__engine'} ? : 0 1 1
unless exists $self->{"__engine"} 0 0 0
if (@_) 1 0 1
exists $self->{'__events'} ? : 0 1 1
unless exists $self->{"__events"} 0 0 0
if (@_) 0 0 0
exists $self->{'__extra_path'} ? : 0 0 0
unless exists $self->{"__extra_path"} 0 0 0
if (@_) 1 1 2
exists $self->{'__fh'} ? : 0 1 1
unless exists $self->{"__fh"} 0 1 1
if (@_) 1 0 1
exists $self->{'__my_name'} ? : 0 1 1
unless exists $self->{"__my_name"} 0 0 0
if (@_) 1 1 2
exists $self->{'__obj'} ? : 0 1 1
unless exists $self->{"__obj"} 0 1 1
if (@_) 1 1 2
exists $self->{'__parent'} ? : 0 1 1
unless exists $self->{"__parent"} 0 1 1
if (@_) 1 0 1
exists $self->{'__path2me'} ? : 0 1 1
unless exists $self->{"__path2me"} 0 0 0
if (@_) 1 1 2
exists $self->{'__post_childs'} ? : 0 1 1
unless exists $self->{"__post_childs"} 0 1 1
if (@_) 1 1 2
exists $self->{'__pre_childs'} ? : 0 1 1
unless exists $self->{"__pre_childs"} 0 1 1
if (@_) 0 0 0
exists $self->{'_args'} ? : 0 0 0
unless exists $self->{"_args"} 0 0 0
if (@_) 12 6 18
exists $self->{'_call_backs'} ? : 0 12 12
unless exists $self->{"_call_backs"} 0 6 6
if (@_) 12 9 21
exists $self->{'_cv_obj'} ? : 0 12 12
unless exists $self->{"_cv_obj"} 0 9 9
if (@_) 1 5 6
exists $self->{'_forced_want_format'} ? : 0 1 1
unless exists $self->{"_forced_want_format"} 3 2 5
if (@_) 12 20 32
exists $self->{'_headers'} ? : 0 12 12
unless exists $self->{"_headers"} 0 20 20
if (@_) 0 0 0
exists $self->{'_is_absolute_url'} ? : 0 0 0
unless exists $self->{"_is_absolute_url"} 0 0 0
if (@_) 0 0 0
exists $self->{'_is_empty'} ? : 0 0 0
unless exists $self->{"_is_empty"} 0 0 0
if (@_) 1 3 4
exists $self->{'_is_file_send'} ? : 0 1 1
unless exists $self->{"_is_file_send"} 1 2 3
if (@_) 2 4 6
exists $self->{'_is_flushed'} ? : 0 2 2
unless exists $self->{"_is_flushed"} 3 1 4
if (@_) 3 4 7
exists $self->{'_is_headers_printed'} ? : 0 3 3
unless exists $self->{"_is_headers_printed"} 4 0 4
if (@_) 2 0 2
exists $self->{'_is_modal'} ? : 0 2 2
unless exists $self->{"_is_modal"} 0 0 0
if (@_) 1 2 3
exists $self->{'_is_need_close_fh'} ? : 0 1 1
unless exists $self->{"_is_need_close_fh"} 0 2 2
if (@_) 1 1 2
exists $self->{'_parsed_cookies'} ? : 0 1 1
unless exists $self->{"_parsed_cookies"} 1 0 1
if (@_) 1 0 1
exists $self->{'_path'} ? : 0 1 1
unless exists $self->{"_path"} 0 0 0
if (@_) 0 0 0
exists $self->{'_raw_html'} ? : 0 0 0
unless exists $self->{"_raw_html"} 0 0 0
if (@_) 4 0 4
exists $self->{'_response_obj'} ? : 0 4 4
unless exists $self->{"_response_obj"} 0 0 0
if (@_) 1 0 1
exists $self->{'_session'} ? : 0 1 1
unless exists $self->{"_session"} 0 0 0
if (@_) 3 5 8
exists $self->{'status'} ? : 0 3 3
unless exists $self->{"status"} 3 2 5
if (@_) 2 3 5
exists $self->{'status'} ? : 0 2 2
unless exists $self->{"status"} 1 2 3
if (@_) 1 1 2
exists $self->{'__conf'} ? : 0 1 1
unless exists $self->{"__conf"} 0 1 1
49 41 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 41 41
50 0 die "ERROR defining and attributes for '$pkg':"
51 . "\n\t$@\n"
52 . "-----------------------------------------------------"
53 . $code;
54 }
55 }
56  
57 =head2 mk_route ( 'route1'=> 'Class::Name', 'route2'=> sub { return new My::Class() })
58  
59 Make route table for object
60  
61 use WebDAO;
62 mk_route(
63 user=>'MyClass::User',
64 test=>sub { return MyClass->new( param1=>1 ) }
65 );
66  
67 =cut
68  
69 sub mk_route {
70 0 ▶ my ($pkg) = caller;
Subroutine mk_route: not called CC=7 SCAR=37.5
Pod documented
71 0 ▶ shift if $_[0] =~ /\:\:/ or $_[0] eq $pkg;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /\:\:/ or $_[0] eq $pkg 0 0 0
Condition0%0/3
$_[0] =~ /\:\:/ or $_[0] eq $pkg
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] =~ /\:\:/ or $_[0] eq $pkg
$_[0] =~ /\:\:/ $_[0] eq $pkg
Truth table0%0/3
A or B
A= $_[0] =~ /\:\:/B= $_[0] eq $pkg
ABresult
1X1
011
000
72 0 my %attrs = @_;
73 9 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
74 0 ▶ while ( my ( $route, $class ) = each %attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %attrs) 0 0 0
75  
76 #check non loaded mods
77 0 my ( $main, $module ) = $class =~ m/(.*\:\:)?(\S+)$/;
78 0 ▶ $main ||= 'main::';
Condition0%0/2
$main ||= "main::"
l!l
00
MC/DC0%0/1
$main ||= "main::"
$main
Truth table0%0/2
A
A= $main
Aresult
11
00
79 0 $module .= '::';
80 0 ▶ unless ( exists $$main{$module} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $main->{$module}) 0 0 0
81 0 _log6("try autoload class $module");
82 0 eval "use $class";
83 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
84 0 carp "Error make route for for class :$class with $@ ";
85 }
86 }
87 }
88 0 %{"${pkg}::_WEBDAO_ROUTE_"} = %attrs;
89 9 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
90 }
91  
92 sub _define_attr_accessor {
93 172 ▶ my ( $pkg, $attr, $default ) = @_;
Subroutine _define_attr_accessor: called CC=1 SCAR=0.0
94  
95 # qq makes this block behave like a double-quoted string
96 172 my $code = qq{
97 package $pkg;
98 sub $attr { # Accessor ...
99 my \$self=shift;
100 if (\@_) {
101 my \$prev = exists \$self->{"$attr"} ? \$self->{"$attr"} : \${"${pkg}::_WEBDAO_ATTRIBUTES_"}{"$attr"};
102 \$self->{"$attr"} = shift ;
103 return \$prev
104 }
105 return \${"${pkg}::_WEBDAO_ATTRIBUTES_"}{"$attr"} unless exists \$self->{"$attr"};
106 \$self->{"$attr"}
107 }
108 };
109 172 $code;
110 }
111  
112  
113 sub new {
114 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
115 0 my $self = {};
116 0 my $stat;
117 0 bless( $self, $class );
118 0 return $self;
119 0 ▶ return ( $stat = $self->_init(@_) ) ? $self : $stat;
Branch: 1 branch
BranchTrueFalseTotal
($stat = $self->_init(@_)) ? : 0 0 0
120 }
121  
122 sub _init {
123 0 ▶ my $self = shift;
Subroutine _init: not called CC=1 SCAR=6.9
124 0 return 1;
125 }
126  
127 #put message into syslog
128 sub _deprecated {
129 0 ▶ my $self = shift;
Subroutine _deprecated: not called CC=2 SCAR=17.9
130 0 my $new_method = shift;
131 0 my ( $old_method, $called_from_str, $called_from_method ) =
132 ( ( caller(1) )[3], ( caller(1) )[2], ( caller(2) )[3] );
133 0 ▶ $called_from_method ||= $0;
Condition0%0/3
$called_from_method ||= $0
l!l&&r!l&&!r
000
MC/DC0%0/2
$called_from_method ||= $0
$called_from_method $0
Truth table0%0/3
A ||= B
A= $called_from_methodB= $0
ABresult
1X1
011
000
134 0 _log3(
135 "called deprecated method $old_method from $called_from_method at line $called_from_str. Use method $new_method instead."
136 );
137 }
138  
139 0 ▶sub _log1 { shift if ref( $_[0] ); _log( level => 1, par => \@_ ) }
Subroutine _log1: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
140 0 ▶sub _log2 { shift if ref( $_[0] ); _log( level => 2, par => \@_ ) }
Subroutine _log2: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
141 0 ▶sub _log3 { shift if ref( $_[0] ); _log( level => 3, par => \@_ ) }
Subroutine _log3: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
142 0 ▶sub _log4 { shift if ref( $_[0] ); _log( level => 4, par => \@_ ) }
Subroutine _log4: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
143 0 ▶sub _log5 { shift if ref( $_[0] ); _log( level => 5, par => \@_ ) }
Subroutine _log5: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
144 0 ▶sub _log6 { shift if ref( $_[0] ); _log( level => 6, par => \@_ ) }
Subroutine _log6: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
145  
146 sub _log {
147 0 ▶ my $dbg_level = $ENV{wdDebug} || $ENV{WD_DEBUG} || 0;
Subroutine _log: not called CC=6 SCAR=37.4
Condition0%0/5
$ENV{'wdDebug'} || $ENV{'WD_DEBUG'} || 0
l!l
00
$ENV{"wdDebug"} or $ENV{"WD_DEBUG"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'wdDebug'} || $ENV{'WD_DEBUG'} || 0
$ENV{"wdDebug"} $ENV{"WD_DEBUG"}
Truth table0%0/3
A or B
A= $ENV{"wdDebug"}B= $ENV{"WD_DEBUG"}
ABresult
1X1
011
000
148 0 ▶ return 0 unless $dbg_level;
Branch: 1 branch
BranchTrueFalseTotal
unless $dbg_level 0 0 0
149 0 ▶ return $dbg_level unless ( scalar @_ );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 0 0 0
150 0 my %args = @_;
151 0 ▶ return $dbg_level if $dbg_level < $args{level};
Branch: 1 branch
BranchTrueFalseTotal
if $dbg_level < $args{"level"} 0 0 0
152 0 my ( $mod_sub, $str ) = ( caller(2) )[ 3, 2 ];
153 0 ($str) = ( caller(1) )[2];
154 0 print STDERR "$$ [$args{level}] $mod_sub:$str @{$args{par}} \n";
155 }
156  
157 9 1;
158 __DATA__
159  
160 =head1 SEE ALSO
161  
162 http://webdao.sourceforge.net
163  
164 =head1 AUTHOR
165  
166 Zahatski Aliaksandr, E<lt>zag@cpan.orgE<gt>
167  
168 =head1 COPYRIGHT AND LICENSE
169  
170 Copyright 2002-2015 by Zahatski Aliaksandr
171  
172 This library is free software; you can redistribute it and/or modify
173 it under the same terms as Perl itself.
174  
175 =cut
« blib/lib/WebDAO/FCGI/ProcManager.pm ↑ Summary blib/lib/WebDAO/Lexer/regclass.pm »