File Coverage

blib/lib/RapidApp/Template/Controller/Dispatch.pm
Criterion Covered Total %
statement 16 27 59.2
branch 0 8 0.0
condition n/a
subroutine 6 7 85.7
pod 0 1 0.0
total 22 43 51.1


line stmt bran cond sub pod time code
1             package RapidApp::Template::Controller::Dispatch;
2 4     4   2787 use strict;
  4         10  
  4         125  
3 4     4   21 use warnings;
  4         8  
  4         131  
4              
5 4     4   22 use RapidApp::Util qw(:all);
  4         10  
  4         2154  
6              
7 4     4   29 use Moose;
  4         9  
  4         28  
8 4     4   23118 use namespace::autoclean;
  4         11  
  4         39  
9              
10             # This is the dispatch controller which maps public URL requests
11             # to the actual Template Controller. It is mounted at the root
12             # of the application if the root module isn't, otherwise, it is
13             # called by the root module via shortcut method
14             # $c->template_dispatcher->default($c,@path) where @path is a
15             # *public* template path that is mapped into a real template path
16              
17 4     4   343 BEGIN { extends 'Catalyst::Controller' }
18              
19             before 'COMPONENT' => sub {
20             my $class = shift;
21             my $app_class = ref $_[0] || $_[0];
22            
23             my $cnf = $app_class->config->{'Model::RapidApp'} || {};
24              
25             $class->config(
26             root_template => $cnf->{root_template} || 'rapidapp/default_root_template.html',
27             root_template_prefix => $cnf->{root_template_prefix},
28             );
29              
30             unless ($app_class->application_has_root_controller) {
31             $class->config( action => {
32             default => { Path => '/' },
33             });
34             }
35              
36             };
37              
38             sub default {
39 0     0 0   my ($self, $c, @args) = @_;
40              
41 0           my $cfg = $self->config;
42            
43             # root '/' request:
44 0 0         if(scalar @args == 0) {
45 0 0         die "root_template not defined" unless ($cfg->{root_template});
46 0           @args = ($cfg->{root_template});
47             }
48             else {
49 0 0         my $prefix = $cfg->{root_template_prefix} or die "No root_template_prefix defined";
50 0 0         @args = ($cfg->{root_template_prefix},@args) unless ($prefix eq '/');
51             }
52            
53 0           $c->stash->{editable} = 1; # <-- Enable template editing (if has perms)
54 0           my $template = join('/',@args);
55 0           $template =~ s/\/+/\//g; #<-- strip any double //
56 0           return $c->template_controller->view($c, $template);
57             }
58              
59             1;