| 1 | package Dancer::Template::Caribou; | ||||||||||
| 2 | 3 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||
| 3 | #ABSTRACT: Template::Caribou wrapper for Dancer | ||||||||||
| 4 | 3 | $Dancer::Template::Caribou::VERSION = '1.0.1'; | |||||||||
| 5 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use Moose::Util qw/ with_traits find_meta /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use Dancer::Config qw/ setting /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use Module::Runtime qw/ use_module /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 3 | extends 'Dancer::Template::Abstract'; | |||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub _build_name { 'Dancer::Template::Caribou' }; | ||||||||
|
Subroutine
_build_name: not called CC=1 SCAR=6.9
| |||||||||||
| 17 | |||||||||||
| 18 | has 'default_tmpl_ext' => ( | ||||||||||
| 19 | is => 'ro', | ||||||||||
| 20 | 2 | ▶ | default => sub { 'bou' }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 3 | ); | |||||||||
| 22 | |||||||||||
| 23 | has default_template => ( | ||||||||||
| 24 | is => 'ro', | ||||||||||
| 25 | lazy => 1, | ||||||||||
| 26 | 2 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 27 | 2 | ▶ | $_[0]->config->{default_template} || 'page'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | }, | ||||||||||
| 29 | 3 | ); | |||||||||
| 30 | |||||||||||
| 31 | has default_layout_template => ( | ||||||||||
| 32 | is => 'ro', | ||||||||||
| 33 | lazy => 1, | ||||||||||
| 34 | 1 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||
| 35 | 1 | ▶ | $_[0]->config->{default_layout_template} || 'page'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | }, | ||||||||||
| 37 | 3 | ); | |||||||||
| 38 | |||||||||||
| 39 | has namespace => ( | ||||||||||
| 40 | is => 'ro', | ||||||||||
| 41 | lazy => 1, | ||||||||||
| 42 | predicate => 'has_namespace', | ||||||||||
| 43 | 1 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||
| 44 | 1 | ▶ | $_[0]->config->{namespace} || 'Dancer::View'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | }, | ||||||||||
| 46 | 3 | ); | |||||||||
| 47 | |||||||||||
| 48 | has layout_namespace => ( | ||||||||||
| 49 | is => 'ro', | ||||||||||
| 50 | lazy => 1, | ||||||||||
| 51 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 52 | $_[0]->config->{layout_namespace} | ||||||||||
| 53 | 0 | ▶ | or $_[0]->namespace . '::Layout'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | }, | ||||||||||
| 55 | 3 | ); | |||||||||
| 56 | |||||||||||
| 57 | 3 | ▶ | sub apply_layout { | ||||||||
|
Subroutine
apply_layout: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 58 | 3 | return $_[1]; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | sub layout { | ||||||||
|
Subroutine
layout: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 62 | 0 | return $_[3]; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 3 | ▶ | sub render { | ||||||||
|
Subroutine
render: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 66 | 3 | my( $self, $template, $tokens ) = @_; | |||||||||
| 67 | |||||||||||
| 68 | 3 | my $class = $template; | |||||||||
| 69 | 3 | ▶ | $class = join '::', $self->namespace, $class | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | unless $class =~ s/^\+//; | ||||||||||
| 71 | |||||||||||
| 72 | 3 | use_module($class); | |||||||||
| 73 | |||||||||||
| 74 | 3 | my $method = $self->default_template; | |||||||||
| 75 | |||||||||||
| 76 | # TODO build a cache of layout + class classes? | ||||||||||
| 77 | 3 | ▶ | if ( my $layout = Dancer::App->current->setting('layout') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 1 | my $layout_class = $layout; | |||||||||
| 79 | 1 | ▶ | $layout_class = join '::', $self->layout_namespace, $layout_class | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | unless $layout_class =~ s/^\+//; | ||||||||||
| 81 | |||||||||||
| 82 | 1 | $class = with_traits( $class, use_module($layout_class) ); | |||||||||
| 83 | 1 | $method = $self->default_layout_template; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 3 | my $x = $class->new( %$tokens)->$method; | |||||||||
| 87 | 3 | ▶ | use utf8;utf8::decode($x); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 88 | 3 | return $x; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 6 | ▶ | sub view { | ||||||||
|
Subroutine
view: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 92 | 6 | my( $self, $view ) = @_; | |||||||||
| 93 | 6 | return $view; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | # TODO check if the class exists | ||||||||||
| 97 | 3 | ▶ | sub view_exists { | ||||||||
|
Subroutine
view_exists: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 98 | 3 | 1; | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | |||||||||||
| 102 | 3 | 1; | |||||||||
| 103 | |||||||||||
| 104 | __END__ | ||||||||||