line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Ex::Recipes; |
2
|
1
|
|
|
1
|
|
27743
|
use utf8; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
5
|
|
3
|
1
|
|
|
1
|
|
32
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
5
|
1
|
|
|
1
|
|
6
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
6
|
1
|
|
|
1
|
|
1030
|
use Data::Dumper; |
|
1
|
|
|
|
|
11808
|
|
|
1
|
|
|
|
|
86
|
|
7
|
1
|
|
|
1
|
|
8
|
use base qw(CGI::Ex::App); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1063
|
|
8
|
1
|
|
|
1
|
|
16318
|
use CGI::Ex::Die register => 1; |
|
1
|
|
|
|
|
11514
|
|
|
1
|
|
|
|
|
9
|
|
9
|
1
|
|
|
1
|
|
235
|
use CGI::Ex::Dump qw(debug dex_warn ctrace dex_trace); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
80
|
|
10
|
1
|
|
|
|
|
1845
|
use CGI::Ex::Recipes::DBIx qw( |
11
|
|
|
|
|
|
|
dbh |
12
|
|
|
|
|
|
|
sql |
13
|
|
|
|
|
|
|
create_tables |
14
|
|
|
|
|
|
|
categories |
15
|
|
|
|
|
|
|
recipes |
16
|
1
|
|
|
1
|
|
584
|
); |
|
1
|
|
|
|
|
4
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub ext_conf { |
21
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
22
|
0
|
0
|
|
|
|
|
$self->{'ext_conf'} = shift if @_ == 1; |
23
|
0
|
|
0
|
|
|
|
return $self->{'ext_conf'} || 'conf'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#overwritten the new (in 2.18)implementation of 'conf' so |
27
|
|
|
|
|
|
|
# the application can find its, given Recipes.conf |
28
|
|
|
|
|
|
|
sub conf { |
29
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
30
|
0
|
0
|
|
|
|
|
$self->{'conf'} = pop if @_ == 1; |
31
|
0
|
|
0
|
|
|
|
return $self->{'conf'} ||= do { |
32
|
0
|
|
0
|
|
|
|
my $conf = $self->conf_obj->read($self->conf_file, {no_warn_on_fail => 1}) || croak $@; |
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
|
0
|
0
|
|
|
|
if ($hash && scalar keys %$hash) { |
37
|
0
|
|
|
|
|
|
my $err_obj = $self->val_obj->validate($conf, $hash); |
38
|
0
|
0
|
|
|
|
|
die $err_obj if $err_obj; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
$conf; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
0
|
1
|
|
sub load_conf { 1 } |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
0
|
1
|
|
sub base_dir_abs {$_[0]->{'base_dir_abs'} || ['./']} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub allow_morph { |
49
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub path_info_map { |
55
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
56
|
0
|
|
0
|
|
|
|
my $step = $self->form->{ $self->step_key } || $self->conf->{default_step}; |
57
|
0
|
|
0
|
|
|
|
return $self->conf->{path_info_map}{$step} || do { |
58
|
|
|
|
|
|
|
my $step = $self->form->{ $self->step_key } || $self->conf->{default_step}; |
59
|
|
|
|
|
|
|
return '' if $step eq $self->conf->{default_step}; |
60
|
|
|
|
|
|
|
[ |
61
|
|
|
|
|
|
|
[ |
62
|
|
|
|
|
|
|
qr{^/$step/(\d+)}, 'id' |
63
|
|
|
|
|
|
|
] |
64
|
|
|
|
|
|
|
]; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#Will be run natively for all subclasses |
69
|
0
|
0
|
|
0
|
1
|
|
sub skip { shift->form->{'id'} ? 0 : 1 } |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#ADDING AUTHENTICATION TO THE ENTIRE APPLICATION |
72
|
|
|
|
|
|
|
sub get_pass_by_user { |
73
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
74
|
0
|
|
|
|
|
|
my $user = shift; |
75
|
0
|
|
|
|
|
|
return $self->conf->{users}{$user}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#ADDING AUTHENTICATION TO INDIVIDUAL STEPS |
79
|
|
|
|
|
|
|
sub require_auth { |
80
|
0
|
|
|
0
|
1
|
|
my ($self, $step) = @_; |
81
|
|
|
|
|
|
|
#allow configuration first |
82
|
0
|
|
0
|
|
|
|
return $self->conf->{require_auth}{$step} || 0; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#get authentication arguments from configuration if there is such |
86
|
|
|
|
|
|
|
sub auth_args { |
87
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
|
|
|
$self->conf->{template_args}, |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$self->conf->{auth_args} |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub hash_base { |
95
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub post_navigate { |
105
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
106
|
|
|
|
|
|
|
# show what happened |
107
|
0
|
0
|
|
|
|
|
if (values %{$self->{'debug'}}) { |
|
0
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
debug $self->dump_history if $self->conf->{debug}{dump_history}; |
109
|
0
|
0
|
|
|
|
|
debug $self->conf if $self->conf->{debug}{conf}; |
110
|
0
|
0
|
|
|
|
|
debug \%ENV if $self->conf->{debug}{ENV}; |
111
|
0
|
0
|
|
|
|
|
debug $self->cookies if $self->conf->{debug}{cookies}; |
112
|
0
|
0
|
|
|
|
|
debug $self->form if $self->conf->{debug}{form}; |
113
|
0
|
0
|
|
|
|
|
debug \%INC if $self->conf->{debug}{INChash}; |
114
|
0
|
0
|
|
|
|
|
debug \@INC if $self->conf->{debug}{INCarray}; |
115
|
0
|
0
|
|
|
|
|
debug $self->{_package} if $self->conf->{debug}{_package}; |
116
|
0
|
0
|
|
|
|
|
debug [sort keys %{$self->{_cache}}] if $self->conf->{debug}{_cache}; |
|
0
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
#or do other usefull things. |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub pre_navigate { |
122
|
|
|
|
|
|
|
#efectively logout |
123
|
0
|
|
|
0
|
1
|
|
require CGI::Ex::Auth; |
124
|
0
|
0
|
|
|
|
|
$_[0]->CGI::Ex::Auth::delete_cookie({'key'=>'cea_user'}) |
125
|
|
|
|
|
|
|
if $_[0]->form->{'logout'}; |
126
|
0
|
|
|
|
|
|
return 0; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub pre_step { |
130
|
0
|
|
|
0
|
1
|
|
$_[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
|
|
|
|
|
|
|
sub step_args { |
139
|
0
|
|
0
|
0
|
1
|
|
return $_[0]->form->{step_args} || do { |
140
|
|
|
|
|
|
|
if($_[0]->form->{step_info}){ |
141
|
|
|
|
|
|
|
my @step_args = split /\//,$_[0]->form->{step_info}; |
142
|
|
|
|
|
|
|
for( my $i = 0 ; $i < @step_args; $i = $i+2 ){ |
143
|
|
|
|
|
|
|
$_[0]->form->{step_args}{$step_args[$i]} = $step_args[$i+1] || ''; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
return $_[0]->form->{step_args} || {}; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
#Returns the cache object. |
151
|
|
|
|
|
|
|
sub cache { |
152
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
153
|
0
|
|
0
|
|
|
|
return $self->{cache} || do { |
154
|
|
|
|
|
|
|
require CGI::Ex::Recipes::Cache; |
155
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
sub strftmime { |
163
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
164
|
0
|
|
|
|
|
|
require POSIX; |
165
|
0
|
|
0
|
|
|
|
POSIX::strftime(shift,localtime( shift||time ) ); |
166
|
|
|
|
|
|
|
} |
167
|
0
|
|
|
0
|
1
|
|
sub now {time}; |
168
|
|
|
|
|
|
|
1; # End of CGI::Ex::Recipes |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
__END__ |