File Coverage

blib/lib/RapidApp/ModuleDispatcher.pm
Criterion Covered Total %
statement 15 15 100.0
branch 1 2 50.0
condition 2 6 33.3
subroutine 4 4 100.0
pod 1 1 100.0
total 23 28 82.1


line stmt bran cond sub pod time code
1             package RapidApp::ModuleDispatcher;
2              
3 4     4   2585 use Moose;
  4         8  
  4         19  
4 4     4   21366 use RapidApp::Util qw(:all);
  4         10  
  4         2086  
5              
6 4     4   29 use Scalar::Util 'blessed';
  4         16  
  4         727  
7              
8             # Which RapidApp module to dispatch to. By default, we dispatch to the root.
9             # If you had multiple ModuleDispatchers, you might choose to dispatch to deeper in the tree.
10             has 'dispatchTarget' => ( is => 'rw', isa => 'Str', default => "/");
11              
12             =head2 $ctlr->dispatch( $c, @args )
13              
14             dispatch takes a catalyst instance, and a list of path arguments. It does some setup work,
15             and then calls "Controller" on the target module to begin handling the arguments.
16              
17             dispatch takes care of the special exception handling/saving, and also sets up the
18             views to display the exceptions.
19              
20             It also is responsible for cleaning temporary values from the Modules after the request is over.
21              
22             =cut
23             sub dispatch {
24 17     17 1 74 my ($self, $c, @args)= @_;
25            
26             # get the root module (or sub-module, if we've been configured that way)
27 17         91 my $targetModule= $c->rapidApp->module($self->dispatchTarget);
28            
29             # now run the controller
30 17         182 my $result = $targetModule->THIS_MODULE->Controller($c, @args);
31 12         54 $c->stash->{controllerResult} = $result;
32            
33             # if the body was not set, make sure a view was chosen
34             defined $c->res->body || defined $c->stash->{current_view} || defined $c->stash->{current_view_instance}
35 12 50 33     763 or die "No view was selected, and a body was not generated";
      33        
36            
37 12         1374 return $result;
38             }
39              
40             1;