Recipes.pm

filter: Statementstmt 29.9% 29 / 97 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 32 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 33.3% 9 / 27 Podpod 100% 18 / 18 totaltotal 24.0% 56 / 233 CC 34 SCAR 36.8
CC
34
Cov
17%
post_navigate
132.0
conf
56.0
step_args
42.0
CRAP 39.6
« Recipes/Template/Menu.pm ↑ Summary Recipes/DBIx.pm »
1 package CGI::Ex::Recipes;
2 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use base qw(CGI::Ex::App);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use CGI::Ex::Die register => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use CGI::Ex::Dump qw(debug dex_warn ctrace dex_trace);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use CGI::Ex::Recipes::DBIx qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
11 dbh
12 sql
13 create_tables
14 categories
15 recipes
16 2 );
17  
18 2 our $VERSION = '0.08';
19  
20 0 ▶sub ext_conf {
Subroutine ext_conf: not called CC=3 SCAR=24.8
Pod documented
21 0 my $self = shift;
22 0 ▶ $self->{'ext_conf'} = shift if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
23 0 ▶ return $self->{'ext_conf'} || 'conf';
Condition0%0/2
$self->{'ext_conf'} || 'conf'
l!l
00
MC/DC0%0/1
$self->{'ext_conf'} || 'conf'
$self->{'ext_conf'}
Truth table0%0/2
A
A= $self->{'ext_conf'}
Aresult
11
00
24 }
25  
26 #overwritten the new (in 2.18)implementation of 'conf' so
27 # the application can find its, given Recipes.conf
28 0 ▶sub conf {
Subroutine conf: not called CC=7 SCAR=40.3
Pod documented
29 0 my $self = shift;
30 0 ▶ $self->{'conf'} = pop if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
31 0 ▶ return $self->{'conf'} ||= do {
Condition0%0/3
$self->{"conf"} ||= do { my $conf = $self->conf_obj->read($self->conf_file, {"no_warn_on_fail", 1}) || croak($@); my $hash = $self->conf_validation; if ($hash and scalar keys %$hash) { my $err_obj = $self->val_obj->validate($conf, $hash); die $err_obj if $err_obj; } ; $conf }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"conf"} ||= do { my $conf = $self->conf_obj->read($self->conf_file, {"no_warn_on_fail", 1}) || croak($@); my $hash = $self->conf_validation; if ($hash and scalar keys %$hash) { my $err_obj = $self->val_obj->validate($conf, $hash); die $err_obj if $err_obj; } ; $conf }
$self->{"conf"} do { my $conf = $self->conf_obj->read($self->conf_file, {"no_warn_on_fail", 1}) || croak($@); my $hash = $self->conf_validation; if ($hash and scalar keys %$hash) { my $err_obj = $self->val_obj->validate($conf, $hash); die $err_obj if $err_obj; } ; $conf }
Truth table0%0/3
A ||= B
A= $self->{"conf"}B= do { my $conf = $self->conf_obj->read($self->conf_file, {"no_warn_on_fail", 1}) || croak($@); my $hash = $self->conf_validation; if ($hash and scalar keys %$hash) { my $err_obj = $self->val_obj->validate($conf, $hash); die $err_obj if $err_obj; } ; $conf }
ABresult
1X1
011
000
32 0 ▶ my $conf = $self->conf_obj->read($self->conf_file, {no_warn_on_fail => 1}) || croak $@;
Condition0%0/2
$self->conf_obj->read($self->conf_file, {'no_warn_on_fail', 1}) || croak($@)
l!l
00
MC/DC0%0/1
$self->conf_obj->read($self->conf_file, {'no_warn_on_fail', 1}) || croak($@)
$self->conf_obj->read($self->conf_file, {'no_warn_on_fail', 1})
Truth table0%0/2
A
A= $self->conf_obj->read($self->conf_file, {'no_warn_on_fail', 1})
Aresult
11
00
33 #my $conf = $self->conf_file;
34 #$conf = ($self->conf_obj->read($conf, {no_warn_on_fail => 1}) || $self->conf_die_on_fail ? croak $@ : {}) if ! $conf;
35 0 my $hash = $self->conf_validation;
36 0 ▶ if ($hash && scalar keys %$hash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash and scalar keys %$hash) 0 0 0
Condition0%0/2
$hash and scalar keys %$hash
!ll
00
MC/DC0%0/1
$hash and scalar keys %$hash
$hash
Truth table0%0/2
A
A= $hash
Aresult
00
11
37 0 my $err_obj = $self->val_obj->validate($conf, $hash);
38 0 ▶ die $err_obj if $err_obj;
Branch: 1 branch
BranchTrueFalseTotal
if $err_obj 0 0 0
39 }
40 0 $conf;
41 }
42 }
43
44 0 ▶sub load_conf { 1 }
Subroutine load_conf: not called CC=1 SCAR=6.9
Pod documented
45  
46 0 ▶sub base_dir_abs {$_[0]->{'base_dir_abs'} || ['./']}
Subroutine base_dir_abs: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"base_dir_abs"} or ["./"] 0 0 0
47  
48 0 ▶sub allow_morph {
Subroutine allow_morph: not called CC=1 SCAR=6.9
Pod documented
49 0 my ( $self, $step ) = @_;
50 0 return $self->conf->{allow_morph}->{$step};
51 }
52  
53 #...but rather override the path_info_map hook for a particular step.
54 0 ▶sub path_info_map {
Subroutine path_info_map: not called CC=5 SCAR=34.0
Pod documented
55 0 my ($self) = @_;
56 0 ▶ my $step = $self->form->{ $self->step_key } || $self->conf->{default_step};
Condition0%0/3
$self->form->{$self->step_key} || $self->conf->{'default_step'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->form->{$self->step_key} || $self->conf->{'default_step'}
$self->form->{$self->step_key} $self->conf->{'default_step'}
Truth table0%0/3
A || B
A= $self->form->{$self->step_key}B= $self->conf->{'default_step'}
ABresult
1X1
011
000
57 0 ▶ return $self->conf->{path_info_map}{$step} || do {
Condition0%0/3
$self->conf->{'path_info_map'}{$step} || do { my $step = $self->form->{$self->step_key} || $self->conf->{'default_step'}; return '' if $step eq $self->conf->{'default_step'}; [[qr"^/$step/(\d+)", 'id']] }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->conf->{'path_info_map'}{$step} || do { my $step = $self->form->{$self->step_key} || $self->conf->{'default_step'}; return '' if $step eq $self->conf->{'default_step'}; [[qr"^/$step/(\d+)", 'id']] }
$self->conf->{'path_info_map'}{$step} do { my $step = $self->form->{$self->step_key} || $self->conf->{'default_step'}; return '' if $step eq $self->conf->{'default_step'}; [[qr"^/$step/(\d+)", 'id']] }
Truth table0%0/3
A || B
A= $self->conf->{'path_info_map'}{$step}B= do { my $step = $self->form->{$self->step_key} || $self->conf->{'default_step'}; return '' if $step eq $self->conf->{'default_step'}; [[qr"^/$step/(\d+)", 'id']] }
ABresult
1X1
011
000
58 0 ▶ my $step = $self->form->{ $self->step_key } || $self->conf->{default_step};
Condition0%0/3
$self->form->{$self->step_key} || $self->conf->{'default_step'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->form->{$self->step_key} || $self->conf->{'default_step'}
$self->form->{$self->step_key} $self->conf->{'default_step'}
Truth table0%0/3
A || B
A= $self->form->{$self->step_key}B= $self->conf->{'default_step'}
ABresult
1X1
011
000
59 0 ▶ return '' if $step eq $self->conf->{default_step};
Branch: 1 branch
BranchTrueFalseTotal
if $step eq $self->conf->{"default_step"} 0 0 0
60 [
61 [
62 0 qr{^/$step/(\d+)}, 'id'
63 ]
64 ];
65 }
66 }
67  
68 #Will be run natively for all subclasses
69 0 ▶sub skip { shift->form->{'id'} ? 0 : 1 }
Subroutine skip: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->form->{'id'} ? : 0 0 0
70  
71 #ADDING AUTHENTICATION TO THE ENTIRE APPLICATION
72 0 ▶sub get_pass_by_user {
Subroutine get_pass_by_user: not called CC=1 SCAR=6.9
Pod documented
73 0 my $self = shift;
74 0 my $user = shift;
75 0 return $self->conf->{users}{$user};
76 }
77  
78 #ADDING AUTHENTICATION TO INDIVIDUAL STEPS
79 0 ▶sub require_auth {
Subroutine require_auth: not called CC=2 SCAR=17.9
Pod documented
80 0 my ($self, $step) = @_;
81 #allow configuration first
82 0 ▶ return $self->conf->{require_auth}{$step} || 0;
Condition0%0/2
$self->conf->{'require_auth'}{$step} || 0
l!l
00
MC/DC0%0/1
$self->conf->{'require_auth'}{$step} || 0
$self->conf->{'require_auth'}{$step}
Truth table0%0/2
A
A= $self->conf->{'require_auth'}{$step}
Aresult
11
00
83 }
84  
85 #get authentication arguments from configuration if there is such
86 0 ▶sub auth_args {
Subroutine auth_args: not called CC=1 SCAR=6.9
Pod documented
87 0 my $self = shift;
88 {
89 0 $self->conf->{template_args},
90 $self->conf->{auth_args}
91 0 };
92 }
93  
94 0 ▶sub hash_base {
Subroutine hash_base: not called CC=1 SCAR=6.9
Pod documented
95 0 my $self = shift;
96 0 my $hash = $self->SUPER::hash_base(@_);
97 0 $hash->{'app'} = $self;
98 #require Scalar::Util;
99 0 Scalar::Util::weaken($hash->{'app'});
100 0 return $hash;
101 }
102  
103  
104 0 ▶sub post_navigate {
Subroutine post_navigate: not called CC=11 SCAR=48.8
Pod documented
105 0 my $self = shift;
106 # show what happened
107 0 ▶ if (values %{$self->{'debug'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (values %{$$self{"debug"};}) 0 0 0
108 0 ▶ debug $self->dump_history if $self->conf->{debug}{dump_history};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"debug"}{"dump_history"} 0 0 0
109 0 ▶ debug $self->conf if $self->conf->{debug}{conf};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"debug"}{"conf"} 0 0 0
110 0 ▶ debug \%ENV if $self->conf->{debug}{ENV};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"debug"}{"ENV"} 0 0 0
111 0 ▶ debug $self->cookies if $self->conf->{debug}{cookies};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"debug"}{"cookies"} 0 0 0
112 0 ▶ debug $self->form if $self->conf->{debug}{form};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"debug"}{"form"} 0 0 0
113 0 ▶ debug \%INC if $self->conf->{debug}{INChash};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"debug"}{"INChash"} 0 0 0
114 0 ▶ debug \@INC if $self->conf->{debug}{INCarray};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"debug"}{"INCarray"} 0 0 0
115 0 ▶ debug $self->{_package} if $self->conf->{debug}{_package};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"debug"}{"_package"} 0 0 0
116 0 ▶ debug [sort keys %{$self->{_cache}}] if $self->conf->{debug}{_cache};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"debug"}{"_cache"} 0 0 0
117 }
118 #or do other usefull things.
119 }
120  
121 0 ▶sub pre_navigate {
Subroutine pre_navigate: not called CC=2 SCAR=17.9
Pod documented
122 #efectively logout
123 0 require CGI::Ex::Auth;
124 $_[0]->CGI::Ex::Auth::delete_cookie({'key'=>'cea_user'})
125 0 ▶ if $_[0]->form->{'logout'};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->form->{"logout"} 0 0 0
126 0 return 0;
127 }
128  
129 0 ▶sub pre_step {
Subroutine pre_step: not called CC=1 SCAR=6.9
Pod documented
130 0 $_[0]->step_args;
131 #run other things here
132 0 return 0;
133 }
134  
135 # hook/method - returns parsed arguments from C<$self->form->{step_info}>
136 #for the curent step
137 # initially called in pre_step
138 0 ▶sub step_args {
Subroutine step_args: not called CC=6 SCAR=37.4
Pod documented
139 0 ▶ return $_[0]->form->{step_args} || do {
Condition0%0/3
$_[0]->form->{'step_args'} || do { if ($_[0]->form->{'step_info'}) { my @step_args = split(m[/], $_[0]->form->{'step_info'}, 0); for (my $i = 0; $i < @step_args; $i = $i + 2) { $_[0]->form->{'step_args'}{$step_args[$i]} = $step_args[$i + 1] || ''; } ; } ; return $_[0]->form->{'step_args'} || {} }
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]->form->{'step_args'} || do { if ($_[0]->form->{'step_info'}) { my @step_args = split(m[/], $_[0]->form->{'step_info'}, 0); for (my $i = 0; $i < @step_args; $i = $i + 2) { $_[0]->form->{'step_args'}{$step_args[$i]} = $step_args[$i + 1] || ''; } ; } ; return $_[0]->form->{'step_args'} || {} }
$_[0]->form->{'step_args'} do { if ($_[0]->form->{'step_info'}) { my @step_args = split(m[/], $_[0]->form->{'step_info'}, 0); for (my $i = 0; $i < @step_args; $i = $i + 2) { $_[0]->form->{'step_args'}{$step_args[$i]} = $step_args[$i + 1] || ''; } ; } ; return $_[0]->form->{'step_args'} || {} }
Truth table0%0/3
A || B
A= $_[0]->form->{'step_args'}B= do { if ($_[0]->form->{'step_info'}) { my @step_args = split(m[/], $_[0]->form->{'step_info'}, 0); for (my $i = 0; $i < @step_args; $i = $i + 2) { $_[0]->form->{'step_args'}{$step_args[$i]} = $step_args[$i + 1] || ''; } ; } ; return $_[0]->form->{'step_args'} || {} }
ABresult
1X1
011
000
140 0 ▶ if($_[0]->form->{step_info}){
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]->form->{"step_info"}) 0 0 0
141 0 my @step_args = split /\//,$_[0]->form->{step_info};
142 0 ▶ for( my $i = 0 ; $i < @step_args; $i = $i+2 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @step_args) 0 0 0
143 0 ▶ $_[0]->form->{step_args}{$step_args[$i]} = $step_args[$i+1] || '';
Condition0%0/2
$step_args[$i + 1] || ''
l!l
00
MC/DC0%0/1
$step_args[$i + 1] || ''
$step_args[$i + 1]
Truth table0%0/2
A
A= $step_args[$i + 1]
Aresult
11
00
144 }
145 }
146 0 ▶ return $_[0]->form->{step_args} || {};
Condition0%0/2
$_[0]->form->{'step_args'} || {}
l!l
00
MC/DC0%0/1
$_[0]->form->{'step_args'} || {}
$_[0]->form->{'step_args'}
Truth table0%0/2
A
A= $_[0]->form->{'step_args'}
Aresult
11
00
147 }
148 }
149  
150 #Returns the cache object.
151 0 ▶sub cache {
Subroutine cache: not called CC=2 SCAR=17.9
Pod documented
152 0 my $self = shift;
153 0 ▶ return $self->{cache} || do {
Condition0%0/3
$self->{'cache'} || do { require CGI::Ex::Recipes::Cache; $self->{'cache'} = 'CGI::Ex::Recipes::Cache'->new({'cache_hash', {}, 'dbh', $self->dbh}) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'cache'} || do { require CGI::Ex::Recipes::Cache; $self->{'cache'} = 'CGI::Ex::Recipes::Cache'->new({'cache_hash', {}, 'dbh', $self->dbh}) }
$self->{'cache'} do { require CGI::Ex::Recipes::Cache; $self->{'cache'} = 'CGI::Ex::Recipes::Cache'->new({'cache_hash', {}, 'dbh', $self->dbh}) }
Truth table0%0/3
A || B
A= $self->{'cache'}B= do { require CGI::Ex::Recipes::Cache; $self->{'cache'} = 'CGI::Ex::Recipes::Cache'->new({'cache_hash', {}, 'dbh', $self->dbh}) }
ABresult
1X1
011
000
154 0 require CGI::Ex::Recipes::Cache;
155 0 $self->{cache} = CGI::Ex::Recipes::Cache->new({ cache_hash =>{}, dbh => $self->dbh });
156 };
157 }
158  
159  
160 #========================== UTIL ==============================
161 #Utility funcions - may be moved to an Util class if needed
162 0 ▶sub strftmime {
Subroutine strftmime: not called CC=2 SCAR=17.9
Pod documented
163 0 my $self = shift;
164 0 require POSIX;
165 0 ▶ POSIX::strftime(shift,localtime( shift||time ) );
Condition0%0/2
shift() || time
l!l
00
MC/DC0%0/1
shift() || time
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
166 }
167 0 ▶sub now {time};
Subroutine now: not called CC=1 SCAR=6.9
Pod documented
168 2 1; # End of CGI::Ex::Recipes
169  
170  
171 __END__
« Recipes/Template/Menu.pm ↑ Summary Recipes/DBIx.pm »