line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gantry::State::Default; |
2
|
|
|
|
|
|
|
require Exporter; |
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
27
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
326
|
|
5
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
200
|
|
6
|
5
|
|
|
5
|
|
26
|
use vars qw( @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS ); |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
6151
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
############################################################ |
9
|
|
|
|
|
|
|
# Variables # |
10
|
|
|
|
|
|
|
############################################################ |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = qw( Exporter ); |
13
|
|
|
|
|
|
|
@EXPORT = qw( |
14
|
|
|
|
|
|
|
state_run |
15
|
|
|
|
|
|
|
state_engine |
16
|
|
|
|
|
|
|
relocate |
17
|
|
|
|
|
|
|
relocate_permanently |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
@EXPORT_OK = qw( ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
############################################################ |
23
|
|
|
|
|
|
|
# Functions # |
24
|
|
|
|
|
|
|
############################################################ |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#------------------------------------------------- |
27
|
|
|
|
|
|
|
# $self->state_run( r_or_cgi, plugin_callbacks ) |
28
|
|
|
|
|
|
|
#------------------------------------------------- |
29
|
|
|
|
|
|
|
sub state_run { |
30
|
0
|
|
|
0
|
1
|
|
my ( $self, $r_or_cgi, $plugin_callbacks ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my ( @p, $p1 ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
eval { |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
if (defined $plugin_callbacks->{ $self->namespace }->{ post_engine_init }) { |
38
|
|
|
|
|
|
|
# Do the plugin callbacks for the 'post_engine_init' phase |
39
|
0
|
|
|
|
|
|
foreach my $cb ( |
40
|
0
|
|
|
|
|
|
@{ $plugin_callbacks->{ $self->namespace }->{ post_engine_init } } |
41
|
|
|
|
|
|
|
) { |
42
|
0
|
|
|
|
|
|
$cb->( $self ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Do the plugin callbacks for the 'pre_init' phase |
47
|
0
|
0
|
|
|
|
|
if (defined $plugin_callbacks->{ $self->namespace }->{ pre_init }) { |
48
|
0
|
|
|
|
|
|
foreach my $cb ( |
49
|
0
|
|
|
|
|
|
@{ $plugin_callbacks->{ $self->namespace }->{ pre_init } } |
50
|
|
|
|
|
|
|
) { |
51
|
0
|
|
|
|
|
|
$cb->( $self, $r_or_cgi ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$self->init( $r_or_cgi ); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
@p = $self->cleanroot( $self->dispatch_location() ); |
58
|
0
|
|
0
|
|
|
|
$p1 = ( shift( @p ) || 'main' ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# set the action |
61
|
0
|
|
|
|
|
|
$self->action( 'do_'. $p1 ); |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if (defined $plugin_callbacks->{ $self->namespace }->{ post_init }) { |
64
|
|
|
|
|
|
|
# Do the plugin callbacks for the 'post_init' phase |
65
|
0
|
|
|
|
|
|
foreach my $cb ( |
66
|
0
|
|
|
|
|
|
@{ $plugin_callbacks->{ $self->namespace }->{ post_init } } |
67
|
|
|
|
|
|
|
) { |
68
|
0
|
|
|
|
|
|
$cb->( $self ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Call do_error and Return |
74
|
0
|
0
|
|
|
|
|
if( $@ ) { |
75
|
0
|
|
|
|
|
|
my $e = $@; |
76
|
0
|
|
|
|
|
|
return( $self->cast_custom_error( $self->custom_error( $e ), $e ) ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# check for response page -- used primarily for caching |
80
|
0
|
0
|
|
|
|
|
if ( $self->gantry_response_page() ) { |
81
|
0
|
|
|
|
|
|
$self->set_content_type(); |
82
|
0
|
|
|
|
|
|
$self->set_no_cache(); |
83
|
0
|
|
|
|
|
|
$self->send_http_header(); |
84
|
0
|
|
|
|
|
|
$self->print_output( $self->gantry_response_page() ); |
85
|
0
|
|
|
|
|
|
return( $self->success_code() ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
eval { |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if (defined $plugin_callbacks->{ $self->namespace }->{ pre_action }) { |
91
|
|
|
|
|
|
|
# Do the plugin callbacks for the 'pre_action' phase |
92
|
0
|
|
|
|
|
|
foreach my $cb ( |
93
|
0
|
|
|
|
|
|
@{ $plugin_callbacks->{ $self->namespace }->{ pre_action } } |
94
|
|
|
|
|
|
|
) { |
95
|
0
|
|
|
|
|
|
$cb->( $self ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Do action if valid |
100
|
0
|
0
|
|
|
|
|
if ( $self->can( $self->action() ) ) { |
|
|
0
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
$self->do_action( $self->action(), @p ); |
102
|
0
|
|
|
|
|
|
$self->cleanup( ); # Cleanup. |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Try default action |
106
|
|
|
|
|
|
|
elsif ( $self->can( 'do_default' ) ) { |
107
|
0
|
|
|
|
|
|
$self->do_action( 'do_default', $p1, @p ); |
108
|
0
|
|
|
|
|
|
$self->cleanup( ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Else return declined |
112
|
|
|
|
|
|
|
else { |
113
|
0
|
|
|
|
|
|
$self->declined( 1 ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
$self->declined( 1 ) if ( $self->is_status_declined( ) ); |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if (defined $plugin_callbacks->{ $self->namespace }->{ post_action }) { |
119
|
|
|
|
|
|
|
# Do the plugin callbacks for the 'post_action' phase |
120
|
0
|
|
|
|
|
|
foreach my $cb ( |
121
|
0
|
|
|
|
|
|
@{ $plugin_callbacks->{ $self->namespace }->{ post_action } } |
122
|
|
|
|
|
|
|
) { |
123
|
0
|
|
|
|
|
|
$cb->( $self ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
}; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Return REDIRECT |
129
|
0
|
0
|
|
|
|
|
return $self->redirect_response() if ( $self->redirect ); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Return DECLINED |
132
|
0
|
0
|
|
|
|
|
return $self->declined_response( $self->action() ) if ( $self->declined ); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Call do_error and Return |
135
|
0
|
0
|
|
|
|
|
if( $@ ) { |
136
|
0
|
|
|
|
|
|
my $e = $@; |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
return( $self->cast_custom_error( $self->custom_error( $e ), $e ) ); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# set http headers |
142
|
0
|
|
|
|
|
|
$self->set_content_type(); |
143
|
0
|
|
|
|
|
|
$self->set_no_cache(); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Call do_process, defined within the template plugin |
146
|
0
|
|
|
|
|
|
eval { |
147
|
0
|
0
|
|
|
|
|
if (defined $plugin_callbacks->{ $self->namespace }->{ pre_process }) { |
148
|
|
|
|
|
|
|
# Do the plugin callbacks for the 'pre_process' phase |
149
|
0
|
|
|
|
|
|
foreach my $cb ( |
150
|
0
|
|
|
|
|
|
@{ $plugin_callbacks->{ $self->namespace }->{ pre_process } } |
151
|
|
|
|
|
|
|
) { |
152
|
0
|
|
|
|
|
|
$cb->( $self ); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
0
|
|
|
|
$self->gantry_response_page( $self->do_process() || '' ); |
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
|
if (defined $plugin_callbacks->{ $self->namespace }->{ post_process }) { |
159
|
|
|
|
|
|
|
# Do the plugin callbacks for the 'post_process' phase |
160
|
0
|
|
|
|
|
|
foreach my $cb ( |
161
|
0
|
|
|
|
|
|
@{ $plugin_callbacks->{ $self->namespace }->{ post_process } } |
162
|
|
|
|
|
|
|
) { |
163
|
0
|
|
|
|
|
|
$cb->( $self ); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
0
|
0
|
|
|
|
|
my $status = $self->status() ? $self->status() : 200; |
168
|
|
|
|
|
|
|
|
169
|
0
|
0
|
|
|
|
|
if ( $status < 400 ) { |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
$self->send_http_header(); |
172
|
0
|
|
|
|
|
|
$self->print_output( $self->gantry_response_page() ); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
} else { |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
$self->cast_custom_error( $self->gantry_response_page() ); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
}; |
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
|
if ( $@ ) { |
182
|
0
|
|
|
|
|
|
my $e = $@; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
$self->do_error( $e ); |
185
|
0
|
|
|
|
|
|
return( $self->cast_custom_error( $self->custom_error( $e ), $e ) ); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
0
|
0
|
|
|
|
|
my $status = $self->status() ? $self->status() : $self->success_code; |
189
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
return $status; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
#------------------------------------------------- |
195
|
|
|
|
|
|
|
# $self->relocate( $location ) |
196
|
|
|
|
|
|
|
#------------------------------------------------- |
197
|
|
|
|
|
|
|
sub relocate { |
198
|
0
|
|
|
0
|
1
|
|
my ( $self, $location ) = ( shift, shift ); |
199
|
|
|
|
|
|
|
|
200
|
0
|
0
|
|
|
|
|
$location = $self->location if ( ! defined $location ); |
201
|
0
|
|
|
|
|
|
$self->redirect( 1 ); # Tag it for the handler to handle nice. |
202
|
0
|
|
|
|
|
|
$self->header_out( 'location', $location ); |
203
|
0
|
|
|
|
|
|
$self->status( $self->status_const( 'REDIRECT' ) ); |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
return( $self->status_const( 'REDIRECT' ) ); |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
} # end relocate |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
#------------------------------------------------- |
210
|
|
|
|
|
|
|
# $self->relocate_permanently( $location ) |
211
|
|
|
|
|
|
|
#------------------------------------------------- |
212
|
|
|
|
|
|
|
sub relocate_permanently { |
213
|
0
|
|
|
0
|
1
|
|
my ( $self, $location ) = ( shift, shift ); |
214
|
|
|
|
|
|
|
|
215
|
0
|
0
|
|
|
|
|
$location = $self->location if ( ! defined $location ); |
216
|
0
|
|
|
|
|
|
$self->header_out( 'location', $location ); |
217
|
0
|
|
|
|
|
|
$self->status( $self->status_const( 'MOVED_PERMANENTLY' ) ); |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
return( $self->status_const( 'MOVED_PERMANENTLY' ) ); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
} # end relocate_permanently |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
#------------------------------------------------- |
224
|
|
|
|
|
|
|
# $self->state_engine |
225
|
|
|
|
|
|
|
#------------------------------------------------- |
226
|
|
|
|
|
|
|
sub state_engine { |
227
|
0
|
|
|
0
|
1
|
|
return __PACKAGE__; |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
} # end state_engine |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
1; |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
__END__ |