Jifty/Web.pm

filter: Statementstmt 9.6% 46 / 476 Branchbran 0.0% 0 / 188 Conditioncond 0.0% 0 / 93 MC/DCmcdc 0.0% 0 / 51 Subroutinesub 19.4% 13 / 67 Podpod 100% 49 / 49 totaltotal 11.6% 108 / 924 CC 146 SCAR 47.8
CC
146
Cov
6%
redirect
506.0
render_template
420.0
url
90.0
CRAP 118.9
« Jifty/Request/Mapper.pm ↑ Summary Jifty/Handle.pm »
1 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Jifty::Web;
5  
6 =head1 NAME
7  
8 Jifty::Web - Web framework for a Jifty application
9  
10 =cut
11  
12 1 ▶use XML::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use CSS::Squish;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Carp qw(carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use base qw/Class::Accessor::Fast Class::Data::Inheritable Jifty::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use vars qw/$SERIAL @JS_INCLUDES/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 __PACKAGE__->mk_accessors(
22 qw(next_page force_redirect request response session temporary_current_user)
23 );
24  
25 __PACKAGE__->mk_classdata($_)
26 1 for qw(cached_css cached_css_digest cached_css_time
27 css_files javascript_libs external_javascript_libs);
28  
29 1 __PACKAGE__->css_files([qw( main.css )]);
30  
31 1 __PACKAGE__->external_javascript_libs([]);
32  
33 1 __PACKAGE__->javascript_libs([qw(
34 json.js
35 jquery-1.4.1.js
36 iutil.js
37 jifty_interface.js
38 jquery_noconflict.js
39 jquery.jgrowl.js
40 facebox.js
41 behaviour.js
42 jifty.js
43 jifty_utils.js
44 jifty_smoothscroll.js
45 calendar.js
46 datetime.js
47 dom-drag.js
48 combobox.js
49 key_bindings.js
50 context_menu.js
51 yui/yahoo.js
52 yui/dom.js
53 yui/event.js
54 yui/calendar.js
55 yui/element-beta.js
56 yui/tabview.js
57 yui/container.js
58 yui/menu.js
59 app.js
60 app_behaviour.js
61 css_browser_selector.js
62 jquery.timepickr.js
63 jquery.ajaxQueue.js
64 jquery.bgiframe.min.js
65 jquery.autocomplete.js
66 ui.core.js
67 ui.sortable.js
68 ordered-list.js
69 uploads.js
70 )]);
71  
72 1 ▶use Class::Trigger;
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 =head1 METHODS
75  
76 =head3 new
77  
78 Creates a new C<Jifty::Web> object
79  
80 =cut
81  
82 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
83 0 my $class = shift;
84 0 my $self = bless {region_stack => []}, $class;
85 0 $self->session(Jifty::Web::Session->new());
86 0 $self->clear_state_variables;
87 0 return ($self);
88 }
89  
90 =head3 mason
91  
92 Returns a L<HTML::Mason::Request> object
93  
94 =cut
95  
96 0 ▶sub mason {
Subroutine mason: not called CC=1 SCAR=0.2
Pod documented
97 1 ▶ use HTML::Mason::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 0 return HTML::Mason::Request->instance;
99 }
100  
101  
102 =head3 out
103  
104 Send a string to the browser.
105  
106 =cut
107  
108 0 ▶sub out {
Subroutine out: not called CC=1 SCAR=6.9
Pod documented
109 0 shift;
110 0 Jifty->handler->buffer->append(@_);
111 }
112  
113  
114 =head3 url
115  
116 Returns the root url of this Jifty application. This is pulled from
117 the configuration file. Takes an optional named path which will
118 form the path part of the resulting URL.
119  
120 =cut
121  
122 0 ▶sub url {
Subroutine url: not called CC=9 SCAR=45.0
Pod documented
123 0 my $self = shift;
124 0 my %args = (scheme => undef,
125 path => undef,
126 @_);
127  
128 0 my $base_uri = URI->new(Jifty->config->framework("Web")->{BaseURL});
129 0 $base_uri->port(Jifty->config->framework("Web")->{Port});
130  
131 0 my $uri;
132  
133 0 my $req = Jifty->web->request;
134 0 ▶ if ($req && $req->uri->host) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req and $req->uri->host) { } 0 0 0
Condition0%0/3
$req and $req->uri->host
!ll&&!rl&&r
000
MC/DC0%0/2
$req and $req->uri->host
$req $req->uri->host
Truth table0%0/3
A and B
A= $reqB= $req->uri->host
ABresult
0X0
100
111
135 0 $uri = $req->uri->clone;
136 0 $uri->path_query('/');
137 }
138 else {
139 0 $uri = $base_uri->clone;
140 }
141  
142 # https is sticky
143 0 ▶ $uri->scheme('https') if $uri->scheme eq 'http' && Jifty->web->is_ssl;
Branch: 1 branch
BranchTrueFalseTotal
if $uri->scheme eq "http" and "Jifty"->web->is_ssl 0 0 0
Condition0%0/3
$uri->scheme eq "http" and "Jifty"->web->is_ssl
!ll&&!rl&&r
000
MC/DC0%0/2
$uri->scheme eq "http" and "Jifty"->web->is_ssl
$uri->scheme eq "http" "Jifty"->web->is_ssl
Truth table0%0/3
A and B
A= $uri->scheme eq "http"B= "Jifty"->web->is_ssl
ABresult
0X0
100
111
144  
145 # If we're generating a URL for an email (really a Jifty::Notification
146 # subclass), force the app's configured URL rather than relying on the
147 # irrelevant current request.
148 0 my $level = 0;
149 0 ▶ while ( my $class = caller($level++) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = CORE::caller $level++) 0 0 0
150 0 ▶ if ( $class->isa("Jifty::Notification") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->isa("Jifty::Notification")) 0 0 0
151 0 $uri = $base_uri->clone;
152 0 last;
153 }
154 }
155  
156 # Always set path and scheme if they're passed explicitly
157 0 ▶ if (defined (my $path = $args{path})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $path = $args{"path"})) 0 0 0
158 # strip off leading '/' because ->canonical provides one
159 0 $path =~ s{^/}{};
160 0 $uri->path_query($path);
161 }
162  
163 0 ▶ $uri->scheme( $args{'scheme'} ) if defined $args{'scheme'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"scheme"} 0 0 0
164  
165 0 return $uri->canonical->as_string;
166 }
167  
168 =head3 static PATH
169  
170 Returns the URL to the static resource PATH, which is generally simply
171 prepending C</static/>. Also prepends the CDN host, if one is
172 configured.
173  
174 =cut
175  
176 0 ▶sub static {
Subroutine static: not called CC=2 SCAR=17.9
Pod documented
177 0 my $class = shift;
178 0 my $path = shift;
179  
180 0 ▶ my $CDN = Jifty->config->framework('Web')->{CDN} || "";
Condition0%0/2
'Jifty'->config->framework('Web')->{'CDN'} || ''
l!l
00
MC/DC0%0/1
'Jifty'->config->framework('Web')->{'CDN'} || ''
'Jifty'->config->framework('Web')->{'CDN'}
Truth table0%0/2
A
A= 'Jifty'->config->framework('Web')->{'CDN'}
Aresult
11
00
181 0 return "$CDN/static/$path";
182 }
183  
184 =head3 serial
185  
186 Returns a unique identifier, guaranteed to be unique within the
187 runtime of a particular process (i.e., within the lifetime of Jifty.pm).
188 There's no sort of global uniqueness guarantee, but it should be good
189 enough for generating things like moniker names.
190  
191 =cut
192  
193 0 ▶sub serial {
Subroutine serial: not called CC=2 SCAR=17.9
Pod documented
194 0 my $class = shift;
195  
196 # We don't use a lexical for the serial number, because then it
197 # would be reset on module refresh
198 0 ▶ $SERIAL ||= 0;
Condition0%0/2
$Jifty::Web::SERIAL ||= 0
l!l
00
MC/DC0%0/1
$Jifty::Web::SERIAL ||= 0
$Jifty::Web::SERIAL
Truth table0%0/2
A
A= $Jifty::Web::SERIAL
Aresult
11
00
199 0 return join('', "S", ++$SERIAL, $$ ); # Start at 1.
200 }
201  
202 =head2 SESSION MANAGEMENT
203  
204 =head3 setup_session
205  
206 Sets up the current C<session> object (a L<Jifty::Web::Session> tied
207 hash). Aborts if the session is already loaded.
208  
209 =cut
210  
211 # Create the Jifty::Web::Session object
212 0 ▶sub setup_session {
Subroutine setup_session: not called CC=2 SCAR=17.9
Pod documented
213 0 my $self = shift;
214  
215 0 ▶ return if $self->session->loaded;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->loaded 0 0 0
216 0 $self->session->load();
217 }
218  
219 =head3 session
220  
221 Returns the current session's hash. In a regular user environment, it
222 persists, but a request can stop that by handing it a regular hash to
223 use.
224  
225  
226 =head2 CURRENT USER
227  
228 =head3 current_user [USER]
229  
230 Getter/setter for the current user; this gets or sets the 'user' key
231 in the session. These are L<Jifty::Record> objects.
232  
233 If a temporary_current_user has been set, will return that instead.
234  
235 If the current application has no loaded current user, we get an empty
236 app-specific C<CurrentUser> object. (This
237 C<ApplicationClass>::CurrentUser class, a subclass of
238 L<Jifty::CurrentUser>, is autogenerated if it doesn't exist).
239  
240 =cut
241  
242 0 ▶sub current_user {
Subroutine current_user: not called CC=9 SCAR=45.0
Pod documented
243 0 my $self = shift;
244 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
245 0 my $currentuser_obj = shift;
246 0 ▶ $self->session->set(
Branch: 1 branch
BranchTrueFalseTotal
$currentuser_obj ? : 0 0 0
247 'user_id' => $currentuser_obj ? $currentuser_obj->id : undef );
248 0 ▶ $self->{current_user} = ( $currentuser_obj || undef );
Condition0%0/2
$currentuser_obj || undef
l!l
00
MC/DC0%0/1
$currentuser_obj || undef
$currentuser_obj
Truth table0%0/2
A
A= $currentuser_obj
Aresult
11
00
249 }
250  
251 0 my $object;
252 0 ▶ if ( defined $self->temporary_current_user ) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $self->temporary_current_user) { } 0 0 0
elsif (defined $self->{'current_user'}) { } 0 0 0
elsif (my $id = $self->session->get('user_id')) { } 0 0 0
elsif ('Jifty'->admin_mode) { } 0 0 0
253 0 return $self->temporary_current_user;
254 } elsif ( defined $self->{current_user} ) {
255 0 return $self->{current_user};
256 } elsif ( my $id = $self->session->get('user_id') ) {
257 0 $object = Jifty->app_class({require => 0}, "CurrentUser")->new( id => $id );
258 } elsif ( Jifty->admin_mode ) {
259 0 $object = Jifty->app_class({require => 0}, "CurrentUser")->superuser;
260 } else {
261 0 $object = Jifty->app_class({require => 0}, "CurrentUser")->new;
262 }
263  
264 # Don't cache the result unless the session had actually been
265 # loaded already.
266 0 ▶ $self->{current_user} = $object if $self->session->loaded;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->loaded 0 0 0
267 0 return $object;
268 }
269  
270 =head3 temporary_current_user [USER]
271  
272 Sets the current request's current_user to USER if set.
273  
274 This value will _not_ be persisted to the session at the end of the
275 request. To restore the original value, set temporary_current_user to
276 undef.
277  
278 =cut
279  
280 =head2 REQUEST
281  
282 =head3 handle_request [REQUEST]
283  
284 This method sets up a current session, and then processes the given
285 L<Jifty::Request> object. If no request object is given, processes
286 the request object in L</request>.
287  
288 Each action on the request is vetted in three ways -- first, it must
289 be marked as C<active> by the L<Jifty::Request> (this is the default).
290 Second, it must be in the set of allowed classes of actions (see
291 L<Jifty::API/is_allowed>). Finally, the action must validate. If it
292 passes all of these criteria, the action is fit to be run.
293  
294 Before they are run, however, the request has a chance to be
295 interrupted and saved away into a continuation, to be resumed at some
296 later point. This is handled by L<Jifty::Request/save_continuation>.
297  
298 If the continuation isn't being saved, then C<handle_request> goes on
299 to run all of the actions. If all of the actions are successful, it
300 looks to see if the request wished to call any continuations, possibly
301 jumping back and re-running a request that was interrupted in the
302 past. This is handled by L<Jifty::Request/call_continuation>.
303  
304 For more details about continuations, see L<Jifty::Continuation>.
305  
306 =cut
307  
308 0 ▶sub handle_request {
Subroutine handle_request: not called CC=8 SCAR=42.8
Pod documented
309 0 my $self = shift;
310 0 ▶ die _("No request to handle") unless Jifty->web->request;
Branch: 1 branch
BranchTrueFalseTotal
unless "Jifty"->web->request 0 0 0
311  
312 0 my ( $valid_actions, $denied_actions )
313 = $self->_validate_request_actions();
314  
315 # In the case where we have a continuation and want to redirect
316 0 ▶ if ( $self->request->continuation_path && Jifty->web->request->argument('_webservice_redirect') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->request->continuation_path and "Jifty"->web->request->argument("_webservice_redirect")) 0 0 0
Condition0%0/3
$self->request->continuation_path and "Jifty"->web->request->argument("_webservice_redirect")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->request->continuation_path and "Jifty"->web->request->argument("_webservice_redirect")
$self->request->continuation_path "Jifty"->web->request->argument("_webservice_redirect")
Truth table0%0/3
A and B
A= $self->request->continuation_pathB= "Jifty"->web->request->argument("_webservice_redirect")
ABresult
0X0
100
111
317 # for continuation - perform internal redirect under webservices
318 0 $self->webservices_redirect($self->request->continuation_path);
319 0 return;
320 }
321  
322 0 $self->request->save_continuation;
323  
324 0 ▶ unless ( $self->request->just_validating ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->request->just_validating) 0 0 0
325 0 $self->_process_valid_actions($valid_actions);
326 0 $self->_process_denied_actions($denied_actions);
327 }
328  
329 # If there's a continuation call, don't do the rest of this
330 0 ▶ return if $self->response->success and $self->request->call_continuation;
Branch: 1 branch
BranchTrueFalseTotal
if $self->response->success and $self->request->call_continuation 0 0 0
Condition0%0/3
$self->response->success and $self->request->call_continuation
!ll&&!rl&&r
000
MC/DC0%0/2
$self->response->success and $self->request->call_continuation
$self->response->success $self->request->call_continuation
Truth table0%0/3
A and B
A= $self->response->successB= $self->request->call_continuation
ABresult
0X0
100
111
331  
332 0 ▶ $self->redirect if $self->redirect_required;
Branch: 1 branch
BranchTrueFalseTotal
if $self->redirect_required 0 0 0
333 0 $self->request->do_mapping;
334 }
335  
336 0 ▶sub _process_denied_actions {
Subroutine _process_denied_actions: not called CC=2 SCAR=17.9
337 0 my $self = shift;
338 0 my $denied_actions = shift;
339  
340 0 for my $request_action (@$denied_actions) {
341 0 my $action = $self->new_action_from_request($request_action);
342 0 $action->deny( "Access Denied for " . ref($action) );
343 0 $self->response->result( $action->moniker => $action->result );
344 }
345 }
346  
347 0 ▶sub _validate_request_actions {
Subroutine _validate_request_actions: not called CC=8 SCAR=42.8
348 0 my $self = shift;
349
350 0 my @valid_actions;
351 my @denied_actions;
352  
353  
354 0 for my $request_action ( $self->request->actions ) {
355 0 $self->log->debug( "Found action "
356 . $request_action->class . " "
357 . $request_action->moniker );
358 0 ▶ next unless $request_action->active;
Branch: 1 branch
BranchTrueFalseTotal
unless $request_action->active 0 0 0
359 0 ▶ next if $request_action->has_run;
Branch: 1 branch
BranchTrueFalseTotal
if $request_action->has_run 0 0 0
360 0 ▶ unless ( $self->request->just_validating ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->request->just_validating) 0 0 0
361 0 ▶ unless ( Jifty->api->is_allowed( $request_action->class ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Jifty"->api->is_allowed($request_action->class)) 0 0 0
362 0 $self->log->warn( "Attempt to call denied action '"
363 . $request_action->class
364 . "'" );
365 0 $self->log->warn( Jifty->api->explain($request_action->class ) );
366 # Possible cross-site request forgery
367 0 ▶ $self->log->error("Action " . $request_action->class . " has been denied because the request is a GET") if $self->request->method eq "GET";
Branch: 1 branch
BranchTrueFalseTotal
if $self->request->method eq "GET" 0 0 0
368 0 push @denied_actions, $request_action;
369 0 next;
370 }
371 }
372  
373 # Make sure we can instantiate the action
374 0 my $action = $self->new_action_from_request($request_action);
375 0 ▶ next unless $action;
Branch: 1 branch
BranchTrueFalseTotal
unless $action 0 0 0
376 0 $request_action->modified(0);
377  
378 # Try validating -- note that this is just the first pass; as
379 # actions are run, they may fill in values which alter
380 # validation of later actions
381 0 $self->log->debug( "Validating action " . ref($action) . " " . $action->moniker );
382 0 $self->response->result( $action->moniker => $action->result );
383 0 $action->validate;
384  
385 0 push @valid_actions, $request_action;
386 }
387
388 0 return (\@valid_actions, \@denied_actions);
389  
390 }
391  
392 0 ▶sub _process_valid_actions {
Subroutine _process_valid_actions: not called CC=8 SCAR=42.8
393 0 my $self = shift;
394 0 my $valid_actions = shift;
395 0 for my $request_action (@$valid_actions) {
396  
397 # Pull the action out of the request (again, since
398 # mappings may have affected parameters). This
399 # returns the cached version unless the request has
400 # been changed by argument mapping from previous
401 # actions (Jifty::Request::Mapper)
402 0 my $action = $self->new_action_from_request($request_action);
403 0 ▶ next unless $action;
Branch: 1 branch
BranchTrueFalseTotal
unless $action 0 0 0
404 0 ▶ if ( $request_action->modified ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request_action->modified) 0 0 0
405  
406 # If the request's action was changed, re-validate
407 0 $action->result( Jifty::Result->new );
408 0 $action->result->action_class( ref $action );
409 0 $self->response->result( $action->moniker => $action->result );
410 0 $self->log->debug( "Re-validating action "
411 . ref($action) . " "
412 . $action->moniker );
413 0 ▶ next unless $action->validate;
Branch: 1 branch
BranchTrueFalseTotal
unless $action->validate 0 0 0
414 }
415  
416 $self->log->debug(
417 0 "Running action " . ref($action) . " " . $action->moniker );
418 0 eval { $action->run; };
419 0 $request_action->has_run(1);
420  
421 0 ▶ if ( my $err = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 0 0
422  
423 # Poor man's exception propagation; we need to get
424 # "LAST RULE" and "ABORT" exceptions back up to the
425 # dispatcher. This is specifically for redirects from
426 # actions
427 0 ▶ die $err if ( $err =~ /^(LAST RULE|ABORT)/ );
Branch: 1 branch
BranchTrueFalseTotal
if $err =~ /^(LAST RULE|ABORT)/ 0 0 0
428 0 $self->log->fatal($err);
429 0 ▶ $action->result->error(
Branch: 1 branch
BranchTrueFalseTotal
'Jifty'->config->framework('DevelMode') ? : 0 0 0
430 Jifty->config->framework("DevelMode")
431 ? $err
432 : _("There was an error completing the request. Please try again later."
433 )
434 );
435 }
436  
437 # Fill in the request with any results that that action
438 # may have yielded.
439 0 $self->request->do_mapping;
440 }
441  
442 }
443  
444 =head3 request [VALUE]
445  
446 Gets or sets the current L<Jifty::Request> object.
447  
448 =head3 response [VALUE]
449  
450 Gets or sets the current L<Jifty::Response> object.
451  
452 =head3 form
453  
454 Returns the current L<Jifty::Web::Form> object, creating one if there
455 isn't one already.
456  
457 =cut
458  
459 0 ▶sub form {
Subroutine form: not called CC=2 SCAR=17.9
Pod documented
460 0 my $self = shift;
461  
462 0 ▶ $self->{form} ||= Jifty::Web::Form->new;
Condition0%0/3
$self->{"form"} ||= "Jifty::Web::Form"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"form"} ||= "Jifty::Web::Form"->new
$self->{"form"} "Jifty::Web::Form"->new
Truth table0%0/3
A ||= B
A= $self->{"form"}B= "Jifty::Web::Form"->new
ABresult
1X1
011
000
463 0 return $self->{form};
464 }
465  
466 =head3 new_action class => CLASS, moniker => MONIKER, order => ORDER, arguments => PARAMHASH
467  
468 Creates a new action (an instance of a subclass of
469 L<Jifty::Action>). The named arguments passed to this method are
470 passed on to the C<new> method of the action named in C<CLASS>.
471 If you pass an odd number of arguments, then the first argument
472 is interpreted as C<class>.
473  
474 =head3 Arguments
475  
476 =over
477  
478 =item class
479  
480 C<CLASS> is L<qualified|Jifty::API/qualify>, and an instance of that
481 class is created, passing the C<Jifty::Web> object, the C<MONIKER>,
482 and any other arguments that C<new_action> was supplied.
483  
484 =item moniker
485  
486 C<MONIKER> is a unique designator of an action on a page. The moniker
487 is content-free and non-fattening, and may be auto-generated. It is
488 used to tie together arguments that relate to the same action.
489  
490 =item order
491  
492 C<ORDER> defines the order in which the action is run, with lower
493 numerical values running first.
494  
495 =item arguments
496  
497 C<ARGUMENTS> are passed to the L<Jifty::Action/new> method. In
498 addition, if the current request (C<< $self->request >>) contains an
499 action with a matching moniker, any arguments that are in that
500 requested action but not in the C<PARAMHASH> list are set. This
501 implements "sticky fields".
502  
503 =back
504  
505 As a contrast to L<Jifty::Web::Form/add_action>, this does not add the
506 action to the current form -- instead, the first form field to be
507 rendered will automatically register the action in the current form
508 field at that time.
509  
510 =cut
511  
512 0 ▶sub new_action {
Subroutine new_action: not called CC=5 SCAR=34.0
Pod documented
513 0 my $self = shift;
514  
515 # Handle new_action('CreateFoo', moniker => 'create_foo')
516 0 ▶ unshift @_, 'class' if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 0 0
517  
518 0 my %args = (
519 class => undef,
520 moniker => undef,
521 arguments => {},
522 current_user => $self->current_user,
523 @_
524 );
525  
526  
527 # "Untaint" -- the implementation class is provided by the client!)
528 # Allows anything that a normal package name allows
529 0 my $class = delete $args{class};
530 0 ▶ unless ( $class =~ /^([0-9a-zA-Z_:]+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ /^([0-9a-zA-Z_:]+)$/) 0 0 0
531 0 $self->log->error( "Bad action implementation class name: ", $class );
532 0 return;
533 }
534 0 $class = $1; # 'untaint'
535  
536 # Prepend the base path (probably "App::Action") unless it's there already
537 0 $class = Jifty->api->qualify($class);
538  
539 # The implementation class is provided by the client, so this
540 # isn't a "shouldn't happen"
541 0 ▶ return unless Jifty::Util->require( $class );
Branch: 1 branch
BranchTrueFalseTotal
unless "Jifty::Util"->require($class) 0 0 0
542  
543 0 my $action;
544 # XXX TODO bullet proof
545 0 eval { $action = $class->new(%args) };
546 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
547 0 my $err = $@;
548 0 $self->log->fatal($err);
549 0 return;
550 }
551  
552 0 $self->{'actions'}{ $action->moniker } = $action;
553  
554 0 return $action;
555 }
556  
557 =head3 new_action_from_request REQUESTACTION
558  
559 Given a L<Jifty::Request::Action>, creates a new action using C<new_action>.
560  
561 =cut
562  
563 0 ▶sub new_action_from_request {
Subroutine new_action_from_request: not called CC=4 SCAR=30.0
Pod documented
564 0 my $self = shift;
565 0 my $req_action = shift;
566 return $self->{'actions'}{ $req_action->moniker } if
567 0 ▶ $self->{'actions'}{ $req_action->moniker } and not $req_action->modified;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"actions"}{$req_action->moniker} and not $req_action->modified 0 0 0
Condition0%0/3
$self->{"actions"}{$req_action->moniker} and not $req_action->modified
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"actions"}{$req_action->moniker} and not $req_action->modified
$self->{"actions"}{$req_action->moniker} not $req_action->modified
Truth table0%0/3
A and not(B)
A= $self->{"actions"}{$req_action->moniker}B= not $req_action->modified
ABresult
0X0
100
111
568 0 ▶ $self->new_action(
Condition0%0/2
$req_action->arguments || {}
l!l
00
MC/DC0%0/1
$req_action->arguments || {}
$req_action->arguments
Truth table0%0/2
A
A= $req_action->arguments
Aresult
11
00
569 class => $req_action->class,
570 moniker => $req_action->moniker,
571 order => $req_action->order,
572 arguments => $req_action->arguments || {}
573 );
574 }
575  
576 =head3 failed_actions
577  
578 Returns an array of L<Jifty::Action> objects, one for each
579 L<Jifty::Request::Action> that is marked as failed in the current
580 response.
581  
582 =cut
583  
584 0 ▶sub failed_actions {
Subroutine failed_actions: not called CC=4 SCAR=30.0
Pod documented
585 0 my $self = shift;
586 0 my @actions;
587 0 for my $req_action ($self->request->actions) {
588 0 ▶ next unless $self->response->result($req_action->moniker);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->response->result($req_action->moniker) 0 0 0
589 0 ▶ next unless $self->response->result($req_action->moniker)->failure;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->response->result($req_action->moniker)->failure 0 0 0
590 0 push @actions, $self->new_action_from_request($req_action);
591 }
592 0 return @actions;
593 }
594  
595 =head3 succeeded_actions
596  
597 As L</failed_actions>, but for actions that completed successfully;
598 less often used.
599  
600 =cut
601  
602 0 ▶sub succeeded_actions {
Subroutine succeeded_actions: not called CC=4 SCAR=30.0
Pod documented
603 0 my $self = shift;
604 0 my @actions;
605 0 for my $req_action ($self->request->actions) {
606 0 ▶ next unless $self->response->result($req_action->moniker);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->response->result($req_action->moniker) 0 0 0
607 0 ▶ next unless $self->response->result($req_action->moniker)->success;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->response->result($req_action->moniker)->success 0 0 0
608 0 push @actions, $self->new_action_from_request($req_action);
609 }
610 0 return @actions;
611 }
612  
613 =head2 REDIRECTS AND CONTINUATIONS
614  
615 =head3 next_page [VALUE]
616  
617 Gets or sets the next page for the framework to show. This is
618 normally set during the C<take_action> method or a L<Jifty::Action>
619  
620 =head3 force_redirect [VALUE]
621  
622 Gets or sets whether we should force a redirect to C<next_page>, even
623 if it's already the current page. You might set this, e.g. to force a
624 redirect after a POSTed action.
625  
626 =head3 redirect_required
627  
628 Returns true if we need to redirect, now that we've processed all the
629 actions. We need a redirect if either C<next_page> is different from
630 the current page, or C<force_redirect> has been set.
631  
632 =cut
633  
634 0 ▶sub redirect_required {
Subroutine redirect_required: not called CC=7 SCAR=40.3
Pod documented
635 0 my $self = shift;
636  
637 0 ▶ return ( 1 ) if $self->force_redirect;
Branch: 1 branch
BranchTrueFalseTotal
if $self->force_redirect 0 0 0
638  
639 0 ▶ if (!$self->request->is_subrequest
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->request->is_subrequest and $self->next_page and $self->next_page ne $self->request->path || $self->request->state_variables || $self->state_variables) { } 0 0 0
Condition0%0/12
not $self->request->is_subrequest and $self->next_page and $self->next_page ne $self->request->path || $self->request->state_variables || $self->state_variables
!ll&&!rl&&r
000
not $self->request->is_subrequest and $self->next_page
!ll&&!rl&&r
000
$self->next_page ne $self->request->path or $self->request->state_variables or $self->state_variables
l!l&&r!l&&!r
000
$self->next_page ne $self->request->path or $self->request->state_variables
l!l&&r!l&&!r
000
MC/DC0%0/5
not $self->request->is_subrequest and $self->next_page and $self->next_page ne $self->request->path || $self->request->state_variables || $self->state_variables
not $self->request->is_subrequest $self->next_page $self->next_page ne $self->request->path $self->request->state_variables $self->state_variables
Truth table0%0/6
not(A) and B and C or D or E
A= not $self->request->is_subrequestB= $self->next_pageC= $self->next_page ne $self->request->pathD= $self->request->state_variablesE= $self->state_variables
ABCDEresult
0XXXX0
10XXX0
110000
111XX1
1101X1
110011
640 and $self->next_page
641 and ( ( $self->next_page ne $self->request->path )
642 or $self->request->state_variables
643 or $self->state_variables )
644 )
645 {
646 0 return (1);
647  
648 } else {
649 0 return undef;
650 }
651 }
652  
653 =head3 webservices_redirect [TO]
654  
655 Handle redirection inside webservices call. This is meant to be
656 hooked by plugin that knows what to do with it.
657  
658 =cut
659  
660 0 ▶sub webservices_redirect {
Subroutine webservices_redirect: not called CC=3 SCAR=24.8
Pod documented
661 0 my ( $self, $to ) = @_;
662 # XXX: move to singlepage plugin
663 0 ▶ my ($spa) = Jifty->find_plugin('Jifty::Plugin::SinglePage') or return;
Branch: 1 branch
BranchTrueFalseTotal
my($spa) = "Jifty"->find_plugin("Jifty::Plugin::SinglePage") or return 0 0 0
664  
665 0 ▶ return if $self->failed_actions;
Branch: 1 branch
BranchTrueFalseTotal
if $self->failed_actions 0 0 0
666  
667 0 Jifty->web->request->remove_state_variable( 'region-'.$spa->region_name );
668 0 Jifty->web->request->add_fragment(
669 name => $spa->region_name,
670 path => $to,
671 arguments => {},
672 wrapper => 0
673 );
674 }
675  
676 =head3 redirect [TO]
677  
678 Redirect to the next page. If you pass this method a parameter, it
679 redirects to that URL rather than B<next_page>.
680  
681 It creates a continuation of where you want to be, and then calls it.
682 If you want to redirect to a page with parameters, pass in a
683 L<Jifty::Web::Form::Clickable> object.
684  
685 =cut
686  
687 0 ▶sub redirect {
Subroutine redirect: not called CC=22 SCAR=62.3
Pod documented
688 0 my $self = shift;
689 0 ▶ my $redir_to = shift || $self->next_page || $self->request->path;
Condition0%0/6
shift() || $self->next_page || $self->request->path
l!l&&r!l&&!r
000
shift() or $self->next_page
l!l&&r!l&&!r
000
MC/DC0%0/3
shift() || $self->next_page || $self->request->path
shift() $self->next_page $self->request->path
Truth table0%0/4
A or B || C
A= shift()B= $self->next_pageC= $self->request->path
ABCresult
1XX1
01X1
0011
0000
690  
691
692 0 my $page;
693  
694 0 ▶ if ( ref $redir_to and $redir_to->isa("Jifty::Web::Form::Clickable")) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $redir_to and $redir_to->isa('Jifty::Web::Form::Clickable')) { } 0 0 0
Condition0%0/3
ref $redir_to and $redir_to->isa("Jifty::Web::Form::Clickable")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $redir_to and $redir_to->isa("Jifty::Web::Form::Clickable")
ref $redir_to $redir_to->isa("Jifty::Web::Form::Clickable")
Truth table0%0/3
A and B
A= ref $redir_toB= $redir_to->isa("Jifty::Web::Form::Clickable")
ABresult
0X0
100
111
695 0 $page = $redir_to;
696 } else {
697  
698 0 $page = Jifty::Web::Form::Clickable->new();
699 #We set this after creation to ensure that plugins that massage clickables don't impact us
700 0 $page->url($redir_to );
701 }
702  
703 0 ▶ carp "Don't include GET parameters in the redirect URL -- use a Jifty::Web::Form::Clickable instead. See L<Jifty::Web/redirect>" if $page->url =~ /\?/;
Branch: 1 branch
BranchTrueFalseTotal
if $page->url =~ /\?/ 0 0 0
704  
705 0 my %overrides = ( @_ );
706 0 $page->parameter($_ => $overrides{$_}) for keys %overrides;
707  
708 0 my @actions = Jifty->web->request->actions;
709  
710 # To submit a Jifty::Action::Redirect, we don't need to serialize a continuation,
711 # unlike any other kind of actions.
712  
713 0 my $redirect_to_url = '' ;
714  
715 0 ▶ if ( (grep { not $_->action_class->isa('Jifty::Action::Redirect') }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not $_->action_class->isa('Jifty::Action::Redirect');} values %{+{$self->response->results};} or $self->request->state_variables or $self->state_variables or $self->request->continuation or grep {$_->active and not $_->class->isa('Jifty::Action::Redirect');} @actions) { } 0 0 0
Condition0%0/12
grep {not $_->action_class->isa("Jifty::Action::Redirect");} values %{+{$self->response->results};} or $self->request->state_variables or $self->state_variables or $self->request->continuation or grep {$_->active and not $_->class->isa("Jifty::Action::Redirect");} @actions
l!l&&r!l&&!r
000
grep {not $_->action_class->isa("Jifty::Action::Redirect");} values %{+{$self->response->results};} or $self->request->state_variables or $self->state_variables or $self->request->continuation
l!l&&r!l&&!r
000
grep {not $_->action_class->isa("Jifty::Action::Redirect");} values %{+{$self->response->results};} or $self->request->state_variables or $self->state_variables
l!l&&r!l&&!r
000
grep {not $_->action_class->isa("Jifty::Action::Redirect");} values %{+{$self->response->results};} or $self->request->state_variables
l!l&&r!l&&!r
000
MC/DC0%0/5
grep {not $_->action_class->isa("Jifty::Action::Redirect");} values %{+{$self->response->results};} or $self->request->state_variables or $self->state_variables or $self->request->continuation or grep {$_->active and not $_->class->isa("Jifty::Action::Redirect");} @actions
grep {not $_->action_class->isa("Jifty::Action::Redirect");} values %{+{$self->response->results};} $self->request->state_variables $self->state_variables $self->request->continuation grep {$_->active and not $_->class->isa("Jifty::Action::Redirect");} @actions
Truth table0%0/6
A or B or C or D or E
A= grep {not $_->action_class->isa("Jifty::Action::Redirect");} values %{+{$self->response->results};}B= $self->request->state_variablesC= $self->state_variablesD= $self->request->continuationE= grep {$_->active and not $_->class->isa("Jifty::Action::Redirect");} @actions
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
716 0 values %{ { $self->response->results } })
717 or $self->request->state_variables
718 or $self->state_variables
719 or $self->request->continuation
720 0 ▶ or grep { $_->active and not $_->class->isa('Jifty::Action::Redirect') } @actions )
Condition0%0/3
$_->active && !$_->class->isa('Jifty::Action::Redirect')
!ll&&!rl&&r
000
MC/DC0%0/2
$_->active && !$_->class->isa('Jifty::Action::Redirect')
$_->active !$_->class->isa('Jifty::Action::Redirect')
Truth table0%0/3
A && not(B)
A= $_->activeB= !$_->class->isa('Jifty::Action::Redirect')
ABresult
0X0
100
111
721 {
722 0 my $request = Jifty::Request->new();
723 $request->add_state_variable( key => $_->key, value => $_->value )
724 0 for $self->request->state_variables;
725 $request->add_state_variable( key => $_, value => $self->{state_variables}->{$_} )
726 0 for keys %{ $self->{state_variables} };
727 0 for (@actions) {
728 0 ▶ my $new_action = $request->add_action(
Condition0%0/3
$_->active && !$_->has_run
!ll&&!rl&&r
000
MC/DC0%0/2
$_->active && !$_->has_run
$_->active !$_->has_run
Truth table0%0/3
A && not(B)
A= $_->activeB= !$_->has_run
ABresult
0X0
100
111
729 moniker => $_->moniker,
730 class => $_->class,
731 order => $_->order,
732 active => $_->active && (not $_->has_run),
733 has_run => $_->has_run,
734 arguments => $_->arguments,
735 );
736  
737 # Clear out filehandles, which don't go thorugh continuations well
738 0 ▶ for (keys %{$new_action->arguments || {}}) {
Condition0%0/2
$new_action->arguments || {}
l!l
00
MC/DC0%0/1
$new_action->arguments || {}
$new_action->arguments
Truth table0%0/2
A
A= $new_action->arguments
Aresult
11
00
739 $new_action->arguments->{$_} = ''
740 if ref($new_action->arguments->{$_}) eq "Fh"
741 0 ▶ || ref($new_action->arguments->{$_}) eq "Jifty::Web::FileUpload";
Branch: 1 branch
BranchTrueFalseTotal
if ref $new_action->arguments->{$_} eq "Fh" or ref $new_action->arguments->{$_} eq "Jifty::Web::FileUpload" 0 0 0
Condition0%0/3
ref $new_action->arguments->{$_} eq "Fh" or ref $new_action->arguments->{$_} eq "Jifty::Web::FileUpload"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $new_action->arguments->{$_} eq "Fh" or ref $new_action->arguments->{$_} eq "Jifty::Web::FileUpload"
ref $new_action->arguments->{$_} eq "Fh" ref $new_action->arguments->{$_} eq "Jifty::Web::FileUpload"
Truth table0%0/3
A or B
A= ref $new_action->arguments->{$_} eq "Fh"B= ref $new_action->arguments->{$_} eq "Jifty::Web::FileUpload"
ABresult
1X1
011
000
742 }
743 }
744 0 my %parameters = ($page->parameters);
745 0 $request->argument($_ => $parameters{$_}) for keys %parameters;
746  
747 # Apache, lighttpd, and HSS all do one pass of unescaping on
748 # PATH_INFO, which is what $request->path is normally set to.
749 # We should replicate that here.
750 0 $request->path( URI::Escape::uri_unescape( $page->url ) );
751 0 $request->request_uri( URI->new($page->url)->path_query );
752 0 $request->method("GET"); # ..effectively.
753 0 $request->scheme($self->request->scheme);
754 0 $request->continuation($self->request->continuation);
755 0 my $cont = Jifty::Continuation->new(
756 request => $request,
757 response => $self->response,
758 parent => $self->request->continuation,
759 );
760 0 $redirect_to_url = $page->url."?J:RETURN=" . $cont->id;
761 } else {
762 0 $redirect_to_url = $page->complete_url;
763 }
764 0 $self->_redirect($redirect_to_url);
765 }
766  
767 0 ▶sub _redirect {
Subroutine _redirect: not called CC=4 SCAR=30.0
768 0 my $self = shift;
769 0 my ($page) = @_;
770  
771 # It's an experimental feature to support redirect within a
772 # region.
773 0 ▶ if ($self->current_region) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->current_region) 0 0 0
774 # If we're within a region stack, we don't really want to
775 # redirect. We want to redispatch. Also reset the things
776 # applied on beofre.
777 0 local $self->{navigation} = undef;
778 0 local $self->{page_navigation} = undef;
779 0 $self->replace_current_region($page);
780 0 Jifty::Dispatcher::_abort();
781 0 return;
782 }
783  
784 0 ▶ if (my $redir = Jifty->web->request->argument('_webservice_redirect')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $redir = "Jifty"->web->request->argument("_webservice_redirect")) 0 0 0
785 0 push @$redir, $page;
786 0 return;
787 }
788 # $page can't lead with // or it assumes it's a URI scheme.
789 0 $page =~ s{^/+}{/};
790  
791 # This is designed to work under CGI or FastCGI; will need an
792 # abstraction for mod_perl
793  
794 # Clear out the output, if any
795 0 Jifty->handler->buffer->clear;
796  
797 0 my $response = Jifty->web->response;
798  
799 0 $self->log->debug("Execing redirect to $page");
800 # Headers..
801 0 $response->header( Location => $page );
802 0 $response->status( 302 );
803  
804 # cookie has to be sent or returning from continuations breaks
805 0 Jifty->web->session->set_cookie;
806  
807 # Mason abort, or dispatcher abort out of here
808 0 ▶ $self->mason->abort if $self->mason;
Branch: 1 branch
BranchTrueFalseTotal
if $self->mason 0 0 0
809 0 Jifty::Dispatcher::_abort();
810 }
811  
812 =head3 caller
813  
814 Returns the L<Jifty::Request> of our enclosing continuation, or an
815 empty L<Jifty::Request> if we are not in a continuation.
816  
817 =cut
818  
819 0 ▶sub caller {
Subroutine caller: not called CC=2 SCAR=17.9
Pod documented
820 0 my $self = shift;
821  
822 0 ▶ return Jifty::Request->new unless $self->request->continuation;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->request->continuation 0 0 0
823 0 return $self->request->continuation->request;
824 }
825  
826 =head2 HTML GENERATION
827  
828 =head3 tangent PARAMHASH
829  
830 If called in non-void context, creates and renders a
831 L<Jifty::Web::Form::Clickable> with the given I<PARAMHASH>, forcing a
832 continuation save.
833  
834 In void context, does a redirect to the URL that the
835 L<Jifty::Web::Form::Clickable> object generates.
836  
837 Both of these versions preserve all state variables by default.
838  
839 =cut
840  
841 0 ▶sub tangent {
Subroutine tangent: not called CC=4 SCAR=30.0
Pod documented
842 0 my $self = shift;
843  
844 0 ▶ if (@_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
845 0 $self->log->error("Jifty::Web->tangent takes a paramhash. Perhaps you passed '".$_[0]."' , rather than 'url => ".$_[0]."'");
846 0 die;
847 }
848 0 my $clickable = Jifty::Web::Form::Clickable->new(
849 returns => { },
850 preserve_state => 1,
851 @_
852 );
853 0 ▶ if ( defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) { } 0 0 0
854 0 return $clickable->generate;
855 } else {
856 0 my $request = Jifty->web->request->clone;
857 0 my %clickable = $clickable->get_parameters;
858 0 $request->argument($_ => $clickable{$_}) for keys %clickable;
859 0 local Jifty->web->{request} = $request;
860 0 Jifty->web->request->save_continuation;
861 }
862 }
863  
864 =head3 goto PARAMHASH
865  
866 Does an instant redirect to the url generated by the
867 L<Jifty::Web::Form::Clickable> object generated by the I<PARAMHASH>.
868  
869 =cut
870  
871 0 ▶sub goto {
Subroutine goto: not called CC=1 SCAR=6.9
Pod documented
872 0 my $self = shift;
873 0 Jifty->web->redirect(
874 Jifty::Web::Form::Clickable->new(@_));
875 }
876  
877 =head3 link PARAMHASH
878  
879 Generates and renders a L<Jifty::Web::Form::Clickable> using the given
880 I<PARAMHASH>.
881  
882 =cut
883  
884 0 ▶sub link {
Subroutine link: not called CC=2 SCAR=17.9
Pod documented
885 0 my $self = shift;
886  
887 0 my $link = Jifty::Web::Form::Clickable->new(@_)->generate;
888  
889 0 ▶ return $link if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 0 0 0
890  
891 0 $link->render;
892 }
893  
894 =head3 return PARAMHASH
895  
896 If called in non-void context, creates and renders a
897 L<Jifty::Web::Form::Clickable> using the given I<PARAMHASH>,
898 additionally defaults to calling the current continuation.
899  
900 Takes an additional argument, C<to>, which can specify a default path
901 to return to if there is no current continuation.
902  
903 In void context, does a redirect to the URL that the
904 L<Jifty::Web::Form::Clickable> object generates.
905  
906 =cut
907  
908 0 ▶sub return {
Subroutine return: not called CC=4 SCAR=30.0
Pod documented
909 0 my $self = shift;
910 0 my %args = (to => undef,
911 @_);
912 0 my $continuation = Jifty->web->request->continuation;
913 0 ▶ if (not $continuation and $args{to}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $continuation and $args{"to"}) 0 0 0
Condition0%0/3
not $continuation and $args{"to"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $continuation and $args{"to"}
not $continuation $args{"to"}
Truth table0%0/3
not(A) and B
A= not $continuationB= $args{"to"}
ABresult
0X0
100
111
914 $continuation = Jifty::Continuation->new(
915 request => Jifty::Request->new(path => $args{to})
916 0 );
917 }
918 0 delete $args{to};
919  
920 0 my $clickable = Jifty::Web::Form::Clickable->new(
921 call => $continuation, %args
922 );
923  
924 0 ▶ if ( defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) { } 0 0 0
925 0 return $clickable->generate;
926 }
927 else {
928 0 $self->redirect($clickable);
929 }
930 }
931  
932  
933 =head2 template_exists PATH
934  
935 Returns true if PATH is a valid template inside your template
936 root. This checks for both Template::Declare and HTML::Mason
937 Templates. Specifically, returns a reference to the handler which can
938 process the template.
939  
940 If PATH is a I<reference> to the path, it will update the path to
941 append C</index.html> if the path in question doesn't exist, but the
942 index does.
943  
944 =cut
945  
946 0 ▶sub template_exists {
Subroutine template_exists: not called CC=6 SCAR=37.4
Pod documented
947 0 my $self = shift;
948 0 my $template = shift;
949  
950 0 ▶ my $value = ref $template ? $$template : $template;
Branch: 1 branch
BranchTrueFalseTotal
ref $template ? : 0 0 0
951  
952 # Strip trailing slashes
953 0 ▶ $value =~ s{/$}{} if $value ne "/";
Branch: 1 branch
BranchTrueFalseTotal
if $value ne "/" 0 0 0
954  
955 0 foreach my $handler ( map {Jifty->handler->view($_)} Jifty->handler->view_handlers ) {
956 0 ▶ if ( my $path = $handler->template_exists($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = $handler->template_exists($value)) 0 0 0
957 0 ▶ $$template = $path if ref $template;
Branch: 1 branch
BranchTrueFalseTotal
if ref $template 0 0 0
958 0 return $handler;
959 }
960 }
961 0 return undef;
962 }
963  
964  
965  
966 1 my %TEMPLATE_CACHE;
967  
968 =head2 render_template PATH, [ARGS]
969  
970 Use our templating system to render a template. Searches through
971 L<Jifty::Handler/view_handlers> to find the first handler which
972 provides the given template, and caches the handler for future
973 requests.
974  
975 Catches errors, and redirects to C</errors/500>; also shows
976 C</errors/404> if the template cannot be found.
977  
978 =cut
979  
980 0 ▶sub render_template {
Subroutine render_template: not called CC=20 SCAR=60.4
Pod documented
981 0 my $self = shift;
982 0 my $template = shift;
983 0 my $args = shift;
984 0 my $handler;
985 my $content;
986 0 ▶ my $void_context = ( defined wantarray ? 0 :1);
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray ? : 0 0 0
987  
988 0 my $requested_template = $template;
989  
990 # Check for ../../../../../etc/passwd
991 0 my $abs_template_path = Jifty::Util->absolute_path( Jifty->config->framework('Web')->{'TemplateRoot'} . $template );
992 0 my $abs_root_path = Jifty::Util->absolute_path( Jifty->config->framework('Web')->{'TemplateRoot'} );
993 0 ▶ $template = "/errors/500"
Branch: 1 branch
BranchTrueFalseTotal
unless $abs_template_path =~ /^\Q$abs_root_path\E/ 0 0 0
994 if $abs_template_path !~ /^\Q$abs_root_path\E/;
995  
996 # Look for a possible handler, and cache it for future requests.
997 # With DevelMode, always look it up.
998 0 ▶ if ( not exists $TEMPLATE_CACHE{$template} or Jifty->config->framework('DevelMode')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $TEMPLATE_CACHE{$template} or "Jifty"->config->framework("DevelMode")) 0 0 0
Condition0%0/3
not exists $TEMPLATE_CACHE{$template} or "Jifty"->config->framework("DevelMode")
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $TEMPLATE_CACHE{$template} or "Jifty"->config->framework("DevelMode")
not exists $TEMPLATE_CACHE{$template} "Jifty"->config->framework("DevelMode")
Truth table0%0/3
not(A) or B
A= not exists $TEMPLATE_CACHE{$template}B= "Jifty"->config->framework("DevelMode")
ABresult
1X1
011
000
999 0 my $found = $template;
1000 0 $handler = $self->template_exists( \$found );
1001 # We don't cache failing URLs, so clients' can't cause us to
1002 # chew up memory by requesting 404's
1003 0 ▶ $TEMPLATE_CACHE{$template} = [ $found, $handler ] if $handler;
Branch: 1 branch
BranchTrueFalseTotal
if $handler 0 0 0
1004 }
1005  
1006 # Dig out the actual template (which could have a "/index.html" on
1007 # it, or what have you) and its handler.
1008 0 ▶ ($template, $handler) = @{$TEMPLATE_CACHE{$template} || [$template, undef] };
Condition0%0/2
$TEMPLATE_CACHE{$template} || [$template, undef]
l!l
00
MC/DC0%0/1
$TEMPLATE_CACHE{$template} || [$template, undef]
$TEMPLATE_CACHE{$template}
Truth table0%0/2
A
A= $TEMPLATE_CACHE{$template}
Aresult
11
00
1009  
1010 # Handle 404's
1011 0 ▶ unless ($handler) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($handler) 0 0 0
1012 0 Jifty->log->debug("Template '$requested_template' couldn't be found");
1013 0 ▶ return $self->render_template("/errors/404") unless defined $template and $template eq "/errors/404";
Branch: 1 branch
BranchTrueFalseTotal
unless defined $template and $template eq "/errors/404" 0 0 0
Condition0%0/3
defined $template and $template eq "/errors/404"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $template and $template eq "/errors/404"
defined $template $template eq "/errors/404"
Truth table0%0/3
A and B
A= defined $templateB= $template eq "/errors/404"
ABresult
0X0
100
111
1014 0 $self->log->warn("Can't find 404 page!");
1015 0 die "ABORT";
1016 }
1017  
1018 0 $self->log->debug("Showing path $template using @{[ref $handler]}");
1019  
1020 0 my $start_depth = Jifty->handler->buffer->depth;
1021  
1022 0 ▶ Jifty->handler->buffer->push( private => 1 ) unless $void_context;
Branch: 1 branch
BranchTrueFalseTotal
unless $void_context 0 0 0
1023  
1024 0 Jifty->handler->call_trigger("before_render_template", $handler, $template);
1025 0 eval { $handler->show($template, $args) };
1026  
1027 # Handle parse errors
1028 0 my $err = $@;
1029  
1030 0 ▶ $content = Jifty->handler->buffer->pop unless $void_context;
Branch: 1 branch
BranchTrueFalseTotal
unless $void_context 0 0 0
1031  
1032 0 Jifty->handler->call_trigger("after_render_template", $handler, $template, $content);
1033  
1034 0 ▶ if ( $err and not (eval { $err->isa('HTML::Mason::Exception::Abort') } or $err =~ /^ABORT/) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($err and not eval { do { $err->isa('HTML::Mason::Exception::Abort') } } || $err =~ /^ABORT/) { } 0 0 0
elsif ($err) { } 0 0 0
Condition0%0/6
$err and not eval { do { $err->isa("HTML::Mason::Exception::Abort") } } || $err =~ /^ABORT/
!ll&&!rl&&r
000
eval { do { $err->isa('HTML::Mason::Exception::Abort') } } || $err =~ /^ABORT/
l!l&&r!l&&!r
000
MC/DC0%0/3
$err and not eval { do { $err->isa("HTML::Mason::Exception::Abort") } } || $err =~ /^ABORT/
$err eval { do { $err->isa('HTML::Mason::Exception::Abort') } } $err =~ /^ABORT/
Truth table0%0/4
A and not(B || C)
A= $errB= eval { do { $err->isa('HTML::Mason::Exception::Abort') } }C= $err =~ /^ABORT/
ABCresult
0XX0
11X0
1010
1001
1035 0 ▶ $self->log->fatal("View error: $err") if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
1036 0 ▶ if ($template eq '/errors/500') {
Branch: 1 branch
BranchTrueFalseTotal
if ($template eq "/errors/500") 0 0 0
1037 0 $self->log->warn("Can't render internal_error: $err");
1038 # XXX Built-in static "oh noes" page?
1039 0 die "ABORT";
1040 }
1041  
1042 # XXX: This may leave a half-written tag open
1043 0 $err->template_stack;
1044 0 ▶ Jifty->handler->buffer->pop while Jifty->handler->buffer->depth > $start_depth;
Branch: 1 branch
BranchTrueFalseTotal
"Jifty"->handler->buffer->depth > $start_depth and do { "Jifty"->handler->buffer->pop } 0 0 0
1045  
1046 # Save the request away, and redirect to an error page
1047 0 Jifty->web->response->error($err);
1048 0 my $c = Jifty::Continuation->new(
1049 request => Jifty->web->request->top_request,
1050 response => Jifty->web->response,
1051 parent => Jifty->web->request->continuation,
1052 );
1053 # Redirect with a continuation
1054 0 Jifty->web->_redirect( "/errors/500?J:C=" . $c->id );
1055 } elsif ($err) {
1056 0 ▶ Jifty->handler->buffer->pop while Jifty->handler->buffer->depth > $start_depth;
Branch: 1 branch
BranchTrueFalseTotal
"Jifty"->handler->buffer->depth > $start_depth and do { "Jifty"->handler->buffer->pop } 0 0 0
1057 0 die "ABORT";
1058  
1059 } else {
1060 0 return $content;
1061 }
1062 }
1063  
1064  
1065 =head3 render_messages [MONIKER]
1066  
1067 Outputs any messages that have been added, in <div id="messages"> and
1068 <div id="errors"> tags. Messages are added by calling
1069 L<Jifty::Result/message>.
1070  
1071 If a moniker is specified, only messages for that moniker
1072 are rendered.
1073  
1074  
1075 =cut
1076  
1077 0 ▶sub render_messages {
Subroutine render_messages: not called CC=2 SCAR=17.9
Pod documented
1078 0 my $self = shift;
1079 0 my $only_moniker = '';
1080 0 ▶ $only_moniker = shift if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
1081  
1082 0 $self->render_error_messages($only_moniker);
1083 0 $self->render_success_messages($only_moniker);
1084  
1085 0 return '';
1086 }
1087  
1088 =head3 render_success_messages [MONIKER]
1089  
1090 Render success messages for the given moniker, or all of them if no
1091 moniker is given.
1092  
1093 =cut
1094  
1095 0 ▶sub render_success_messages {
Subroutine render_success_messages: not called CC=1 SCAR=6.9
Pod documented
1096 0 my $self = shift;
1097 0 my $moniker = shift;
1098  
1099 0 $self->_render_messages('message', $moniker);
1100  
1101 0 return '';
1102 }
1103  
1104 =head3 render_error_messages [MONIKER]
1105  
1106 Render error messages for the given moniker, or all of them if no
1107 moniker is given.
1108  
1109 =cut
1110  
1111 0 ▶sub render_error_messages {
Subroutine render_error_messages: not called CC=1 SCAR=6.9
Pod documented
1112 0 my $self = shift;
1113 0 my $moniker = shift;
1114  
1115 0 $self->_render_messages('error', $moniker);
1116  
1117 0 return '';
1118 }
1119  
1120 =head3 _render_messages TYPE [MONIKER]
1121  
1122 Output any messages of the given TYPE (either 'error' or 'message') in
1123 a <div id="TYPEs"> tag. If a moniker is given, only renders messages
1124 for that action. Internal helper for L</render_success_messages> and
1125 L</render_errors>.
1126  
1127 =cut
1128  
1129 0 ▶sub _render_messages {
Subroutine _render_messages: not called CC=8 SCAR=42.8
1130 0 my $self = shift;
1131 0 my $type = shift;
1132 0 ▶ my $only_moniker = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1133  
1134 0 my %results = $self->response->results;
1135  
1136 0 ▶ %results = ($only_moniker => $results{$only_moniker}) if $only_moniker;
Branch: 1 branch
BranchTrueFalseTotal
if $only_moniker 0 0 0
1137  
1138 0 ▶ return unless grep {$_->$type()} values %results;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_->$type;} values %results 0 0 0
1139
1140 0 my $plural = $type . "s";
1141 0 $self->out(qq{<div class="jifty results messages" id="$plural">});
1142
1143 0 foreach my $moniker ( sort keys %results ) {
1144 0 ▶ if ( my $text = $results{$moniker}->$type() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $text = $results{$moniker}->$type) 0 0 0
1145 0 ▶ if ( ref $text eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $text eq 'ARRAY') { } 0 0 0
elsif (ref $text) { } 0 0 0
1146 0 $text = join '', @$text;
1147 }
1148 elsif ( ref $text ) {
1149 0 $self->log->warn(
1150 ref($text) . " reference provided as result $type "
1151 0 . "for action $moniker (@{[$results{$moniker}->action_class]})"
1152 );
1153 }
1154 0 $self->out( qq{<div class="$type $moniker">$text</div>} );
1155 }
1156 }
1157 0 $self->out(qq{</div>});
1158 }
1159  
1160 =head3 query_string KEY => VALUE [, KEY => VALUE [, ...]]
1161  
1162 Returns an URL-encoded query string piece representing the arguments
1163 passed to it.
1164  
1165 =cut
1166  
1167 0 ▶sub query_string {
Subroutine query_string: not called CC=2 SCAR=17.9
Pod documented
1168 0 my $self = shift;
1169 0 my %args = @_;
1170 0 my @params;
1171 0 ▶ while ( ( my $key, my $value ) = each %args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 0 0
1172 0 push @params,
1173 $key . "=" . $self->escape_uri( $value );
1174 }
1175 0 return ( join( ';', @params ) );
1176 }
1177  
1178 =head3 escape STRING
1179  
1180 HTML-escapes the given string and returns it
1181  
1182 =cut
1183  
1184 0 ▶sub escape {
Subroutine escape: not called CC=1 SCAR=2.2
Pod documented
1185 1 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1186 0 my $self = shift;
1187 0 return join '', map {my $html = $_; Jifty::View::Mason::Handler::escape_utf8( \$html ); $html} @_;
1188 }
1189  
1190 =head3 escape_uri STRING
1191  
1192 URI-escapes the given string and returns it
1193  
1194 =cut
1195  
1196 0 ▶sub escape_uri {
Subroutine escape_uri: not called CC=1 SCAR=2.2
Pod documented
1197 1 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1198 0 my $self = shift;
1199 0 return join '', map {my $uri = $_; Jifty::View::Mason::Handler::escape_uri( \$uri ); $uri} @_;
1200 }
1201  
1202 =head3 navigation
1203  
1204 Returns the L<Jifty::Web::Menu> for this web request; one is
1205 automatically created if it hasn't been already.
1206  
1207 =cut
1208  
1209 0 ▶sub navigation {
Subroutine navigation: not called CC=2 SCAR=17.9
Pod documented
1210 0 my $self = shift;
1211 0 ▶ if (!$self->{navigation}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"navigation"}) 0 0 0
1212 0 $self->{navigation} = Jifty::Web::Menu->new();
1213 }
1214 0 return $self->{navigation};
1215 }
1216  
1217 =head3 page_navigation
1218  
1219 Returns the L<Jifty::Web::Menu> for this web request; one is
1220 automatically created if it hasn't been already. This is useful
1221 for separating page-level navigation from app-level navigation.
1222  
1223 =cut
1224  
1225 0 ▶sub page_navigation {
Subroutine page_navigation: not called CC=2 SCAR=17.9
Pod documented
1226 0 my $self = shift;
1227 0 ▶ if (!$self->{page_navigation}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"page_navigation"}) 0 0 0
1228 0 $self->{page_navigation} = Jifty::Web::Menu->new();
1229 }
1230 0 return $self->{page_navigation};
1231 }
1232  
1233 =head3 include_css
1234  
1235 Returns a C<< <link> >> tag for the compressed CSS
1236  
1237 =cut
1238  
1239 0 ▶sub include_css {
Subroutine include_css: not called CC=3 SCAR=24.8
Pod documented
1240 0 my $self = shift;
1241  
1242 # if there's no trigger, 0 is returned. if aborted/handled, undef
1243 # is returned.
1244 0 ▶ if ( defined $self->call_trigger( 'include_css', @_ )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->call_trigger("include_css", @_)) 0 0 0
1245 $self->out( qq[<link rel="stylesheet" type="text/css" href="].Jifty->web->static("css/$_").qq[" />\n] )
1246 0 for @{ Jifty->web->css_files };
1247 }
1248  
1249 0 $self->call_trigger('after_include_css', @_);
1250  
1251 0 return '';
1252 }
1253  
1254 =head3 add_css FILE1, FILE2, ...
1255  
1256 Pushes files onto C<< Jifty->web->css_files >>
1257  
1258 =cut
1259  
1260 0 ▶sub add_css {
Subroutine add_css: not called CC=1 SCAR=6.9
Pod documented
1261 0 my $self = shift;
1262 Jifty->web->css_files([
1263 0 @{ Jifty->web->css_files },
1264 @_
1265 ]);
1266 }
1267  
1268 =head3 include_javascript
1269  
1270 Returns a C<< <script> >> tag for the compressed Javascript.
1271  
1272 Your application specific javascript goes in
1273 F<share/web/static/js/app.js>. This will be automagically included if
1274 it exists.
1275  
1276 If you want to add javascript behaviour to your page using CSS
1277 selectors then put your behaviour rules in
1278 F<share/web/static/js/app_behaviour.js> which will also be
1279 automagically included if it exists. The C<behaviour.js> library is
1280 included by Jifty. For more information on C<behaviour.js> see
1281 L<http://bennolan.com/behaviour/>.
1282  
1283 However if you want to include other javascript libraries you need to
1284 add them to the javascript_libs array of your application. Do this in
1285 the C<start> sub of your main application class. For example if your
1286 application is Foo then in L<lib/Foo.pm>
1287  
1288 sub start {
1289 Jifty->web->add_javascript(qw( jslib1.js jslib2.js ) );
1290 }
1291  
1292 The L<add_javascript> method will append the files to javascript_libs.
1293 If you need a different order, you'll have to massage javascript_libs
1294 directly.
1295  
1296 Jifty will look for javascript libraries under F<share/web/static/js/> by
1297 default as well as any plugin static roots.
1298  
1299 =cut
1300  
1301 0 ▶sub include_javascript {
Subroutine include_javascript: not called CC=4 SCAR=30.0
Pod documented
1302 0 my $self = shift;
1303  
1304 0 for my $url ( @{ __PACKAGE__->external_javascript_libs } ) {
1305 0 $self->out(
1306 qq[<script type="text/javascript" src="$url"></script>\n]
1307 );
1308 }
1309  
1310 # if there's no trigger, 0 is returned. if aborted/handled, undef
1311 # is returned.
1312 0 ▶ if ( defined $self->call_trigger('include_javascript', @_) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->call_trigger("include_javascript", @_)) 0 0 0
1313 0 for my $file ( @{ __PACKAGE__->javascript_libs } ) {
1314 0 $self->out(
1315 qq[<script type="text/javascript" src="].Jifty->web->static("js/$file").qq["></script>\n]
1316 );
1317 }
1318 }
1319  
1320 0 $self->call_trigger('after_include_javascript', @_);
1321  
1322 0 return '';
1323 }
1324  
1325 =head3 add_javascript FILE1, FILE2, ...
1326  
1327 Pushes files onto C<< Jifty->web->javascript_libs >>
1328  
1329 =cut
1330  
1331 0 ▶sub add_javascript {
Subroutine add_javascript: not called CC=1 SCAR=6.9
Pod documented
1332 0 my $self = shift;
1333 0 Jifty->web->javascript_libs([ @{ Jifty->web->javascript_libs }, @_ ]);
1334 }
1335  
1336 =head3 remove_javascript FILE1, FILE2, ...
1337  
1338 Removes the given files from C<< Jifty->web->javascript_libs >>.
1339  
1340 This is intended for plugins or applications that provide another version of
1341 the functionality given in our default JS libraries. For example, the CSSQuery
1342 plugin will get rid of the F<cssQuery-jQuery.js> back-compat script.
1343  
1344 =cut
1345  
1346 0 ▶sub remove_javascript {
Subroutine remove_javascript: not called CC=1 SCAR=6.9
Pod documented
1347 0 my $self = shift;
1348 0 my %remove = map { $_ => 1 } @_;
1349  
1350 Jifty->web->javascript_libs([
1351 0 grep { !$remove{$_} } @{ Jifty->web->javascript_libs }
1352 ]);
1353 }
1354  
1355 =head3 add_external_javascript URL1, URL2, ...
1356  
1357 Pushes URLs onto C<< Jifty->web->external_javascript_libs >>
1358  
1359 =cut
1360  
1361 0 ▶sub add_external_javascript {
Subroutine add_external_javascript: not called CC=1 SCAR=6.9
Pod documented
1362 0 my $self = shift;
1363 Jifty->web->external_javascript_libs([
1364 0 @{ Jifty->web->external_javascript_libs }, @_ ]);
1365 }
1366  
1367 =head2 STATE VARIABLES
1368  
1369 =head3 get_variable NAME
1370  
1371 Gets a page specific variable from the request object.
1372  
1373 =cut
1374  
1375 0 ▶sub get_variable {
Subroutine get_variable: not called CC=2 SCAR=17.9
Pod documented
1376 0 my $self = shift;
1377 0 my $name = shift;
1378 0 my $var = $self->request->state_variable($name);
1379 0 ▶ return undef unless ($var);
Branch: 1 branch
BranchTrueFalseTotal
unless $var 0 0 0
1380 0 return $var->value();
1381  
1382 }
1383  
1384 =head3 set_variable NAME VALUE
1385  
1386 Takes a key-value pair for variables to serialize and hand off to the next page.
1387  
1388 Behind the scenes, these variables get serialized into every link or
1389 form that is marked as 'state preserving'. See
1390 L<Jifty::Web::Form::Clickable>.
1391  
1392 Passing C<undef> as a value will remove the variable
1393  
1394 =cut
1395  
1396 0 ▶sub set_variable {
Subroutine set_variable: not called CC=2 SCAR=17.9
Pod documented
1397 0 my $self = shift;
1398 0 my $name = shift;
1399 0 my $value = shift;
1400  
1401 0 ▶ if (!defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value) { } 0 0 0
1402 0 delete $self->{state_variables}{$name};
1403 } else {
1404 0 $self->{state_variables}{$name} = $value;
1405 }
1406  
1407 }
1408  
1409 =head3 state_variables
1410  
1411 Returns all of the state variables that have been set for the next
1412 request, as a hash;
1413  
1414 N.B. These are B<not> prefixed with C<J:V->, as they were in earlier
1415 versions of Jifty
1416  
1417 =cut
1418  
1419 0 ▶sub state_variables {
Subroutine state_variables: not called CC=1 SCAR=6.9
Pod documented
1420 0 my $self = shift;
1421 0 return %{ $self->{state_variables} };
1422 }
1423  
1424 =head3 clear_state_variables
1425  
1426 Remove all the state variables to be serialized for the next request.
1427  
1428 =cut
1429  
1430 0 ▶sub clear_state_variables {
Subroutine clear_state_variables: not called CC=1 SCAR=6.9
Pod documented
1431 0 my $self = shift;
1432  
1433 0 $self->{state_variables} = {};
1434 }
1435  
1436 =head2 REGIONS
1437  
1438 =head3 get_region [QUALIFIED NAME]
1439  
1440 Given a fully C<QUALIFIED NAME> of a region, returns the
1441 L<Jifty::Web::PageRegion> with that name, or undef if no such region
1442 exists.
1443  
1444 =cut
1445  
1446 0 ▶sub get_region {
Subroutine get_region: not called CC=1 SCAR=6.9
Pod documented
1447 0 my $self = shift;
1448 0 my ($name) = @_;
1449 0 return $self->{'regions'}{$name};
1450 }
1451  
1452 =head3 region PARAMHASH
1453  
1454 The provided PARAMHASH is used to create and render a
1455 L<Jifty::Web::PageRegion>; the C<PARAMHASH> is passed directly to its
1456 L<Jifty::Web::PageRegion/new> method, and then
1457 L<Jifty::Web::PageRegion/render> is called.
1458  
1459 =cut
1460  
1461 0 ▶sub region {
Subroutine region: not called CC=2 SCAR=17.9
Pod documented
1462 0 my $self = shift;
1463  
1464 # Create a region
1465 0 ▶ my $region = Jifty::Web::PageRegion->new(@_) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $region = "Jifty::Web::PageRegion"->new(@_) or return 0 0 0
1466  
1467 # Render it
1468 0 $region->render;
1469 }
1470  
1471  
1472 =head3 replace_current_region PATH
1473  
1474 Replaces the current region with a new region and renders it Returns undef if there's no current region
1475  
1476 =cut
1477  
1478 0 ▶sub replace_current_region {
Subroutine replace_current_region: not called CC=2 SCAR=17.9
Pod documented
1479 0 my $self = shift;
1480 0 my $path = shift;
1481 0 ▶ return undef unless (my $region = $self->current_region);
Branch: 1 branch
BranchTrueFalseTotal
unless my $region = $self->current_region 0 0 0
1482 0 $region->force_path($path);
1483 0 $region->render;
1484 }
1485  
1486  
1487 =head3 current_region
1488  
1489 Returns the current L<Jifty::Web::PageRegion>, or undef if there is
1490 none.
1491  
1492 =cut
1493  
1494 0 ▶sub current_region {
Subroutine current_region: not called CC=2 SCAR=17.9
Pod documented
1495 0 my $self = shift;
1496 return $self->{'region_stack'}
1497 0 ▶ ? $self->{'region_stack'}[-1]
Branch: 1 branch
BranchTrueFalseTotal
$self->{'region_stack'} ? : 0 0 0
1498 : undef;
1499 }
1500  
1501 =head3 qualified_region [REGION]
1502  
1503 Returns the fully qualified name of the current
1504 L<Jifty::Web::PageRegion>, or the empty string if there is none. If
1505 C<REGION> is supplied, gives the qualified name of C<REGION> were it
1506 placed in the current region. You may also use a literal region name.
1507  
1508 =cut
1509  
1510 0 ▶sub qualified_region {
Subroutine qualified_region: not called CC=3 SCAR=24.8
Pod documented
1511 0 my $self = shift;
1512 join "-",
1513 0 ▶ map { ref($_) ? $_->name : $_ }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
1514 0 ▶ @{ $self->{'region_stack'} || [] }, @_;
Condition0%0/2
$self->{'region_stack'} || []
l!l
00
MC/DC0%0/1
$self->{'region_stack'} || []
$self->{'region_stack'}
Truth table0%0/2
A
A= $self->{'region_stack'}
Aresult
11
00
1515 }
1516  
1517 =head3 qualified_parent_region [REGION]
1518  
1519 Returns the fully qualified name of the current
1520 L<Jifty::Web::PageRegion>'s parent, or the empty string if there is none. If
1521 C<REGION> is supplied, gives the qualified name of C<REGION> were it
1522 placed in the parent region. You may also use a literal region name.
1523  
1524 =cut
1525  
1526 0 ▶sub qualified_parent_region {
Subroutine qualified_parent_region: not called CC=3 SCAR=24.8
Pod documented
1527 0 my $self = shift;
1528 0 ▶ my @region_stack = @{ $self->{'region_stack'} || [] };
Condition0%0/2
$self->{'region_stack'} || []
l!l
00
MC/DC0%0/1
$self->{'region_stack'} || []
$self->{'region_stack'}
Truth table0%0/2
A
A= $self->{'region_stack'}
Aresult
11
00
1529 0 pop @region_stack;
1530  
1531 join "-",
1532 0 ▶ map { ref($_) ? $_->name : $_ }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
1533 @region_stack, @_;
1534 }
1535  
1536 =head2 is_ssl
1537  
1538 Indicates whether the current request was made using SSL.
1539  
1540 =cut
1541  
1542 0 ▶sub is_ssl { Jifty->web->request && Jifty->web->request->secure }
Subroutine is_ssl: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
"Jifty"->web->request and "Jifty"->web->request->secure 0 0 0
1543  
1544 1 1;
« Jifty/Request/Mapper.pm ↑ Summary Jifty/Handle.pm »