| 1 | package Dancer::Template::TemplateDeclare; | ||||||||||||
| 2 | 4 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 4 | $Dancer::Template::TemplateDeclare::AUTHORITY = 'cpan:YANICK'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | { | ||||||||||||
| 6 | 4 | $Dancer::Template::TemplateDeclare::VERSION = '0.3.2'; | |||||||||||
| 7 | } | ||||||||||||
| 8 | # ABSTRACT: Template::Declare wrapper for Dancer | ||||||||||||
| 9 | |||||||||||||
| 10 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 4 | ▶ | use FindBin; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 4 | ▶ | use Template::Declare; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 4 | ▶ | use Dancer::Config 'setting'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | 4 | ▶ | use base 'Dancer::Template::Abstract'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | |||||||||||||
| 17 | 3 | ▶ | sub init { | ||||||||||
|
Subroutine
init: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 18 | 3 | my $self = shift; | |||||||||||
| 19 | 3 | ▶ | my %config = %{$self->config || {}}; | ||||||||||
|
Condition50%1/2
$self->config || {}
MC/DC0%0/1
$self->config || {}
$self->config
Truth table50%1/2
A
A= $self->config
| |||||||||||||
| 20 | |||||||||||||
| 21 | 3 | my %args = @_; | |||||||||||
| 22 | |||||||||||||
| 23 | 3 | @config{keys %args} = values %args; | |||||||||||
| 24 | |||||||||||||
| 25 | 3 | ▶ | eval "use $_; 1;" or die $@ for @{ $config{dispatch_to} }; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||
| 26 | |||||||||||||
| 27 | 3 | Template::Declare->init(%config); | |||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | 0 | ▶ | sub default_tmpl_ext { return 'DUMMY'; } # because Dancer requires an ext | ||||||||||
|
Subroutine
default_tmpl_ext: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 31 | |||||||||||||
| 32 | 3 | ▶ | sub view_exists { return 1; } | ||||||||||
|
Subroutine
view_exists: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 33 | |||||||||||||
| 34 | 6 | ▶ | sub view { return $_[1] } | ||||||||||
|
Subroutine
view: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 35 | |||||||||||||
| 36 | 5 | ▶ | sub render { | ||||||||||
|
Subroutine
render: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 37 | 5 | my ($self, $template, $tokens) = @_; | |||||||||||
| 38 | |||||||||||||
| 39 | 5 | return Template::Declare->show( $template => $tokens ); | |||||||||||
| 40 | } | ||||||||||||
| 41 | |||||||||||||
| 42 | 2 | ▶ | sub layout { | ||||||||||
|
Subroutine
layout: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 43 | 2 | my ($self, $layout, $tokens, $content) = @_; | |||||||||||
| 44 | |||||||||||||
| 45 | 2 | return Template::Declare->show( | |||||||||||
| 46 | join( '/', 'layout', $layout ) => { | ||||||||||||
| 47 | %$tokens, content => $content | ||||||||||||
| 48 | } | ||||||||||||
| 49 | ); | ||||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | 4 | 1; | |||||||||||
| 53 | |||||||||||||
| 54 | |||||||||||||
| 55 | |||||||||||||
| 56 | =pod | ||||||||||||
| 57 | |||||||||||||
| 58 | =head1 NAME | ||||||||||||
| 59 | |||||||||||||
| 60 | Dancer::Template::TemplateDeclare - Template::Declare wrapper for Dancer | ||||||||||||
| 61 | |||||||||||||
| 62 | =head1 VERSION | ||||||||||||
| 63 | |||||||||||||
| 64 | version 0.3.2 | ||||||||||||
| 65 | |||||||||||||
| 66 | =head1 SYNOPSIS | ||||||||||||
| 67 | |||||||||||||
| 68 | # in 'config.yml' | ||||||||||||
| 69 | template: 'TemplateDeclare' | ||||||||||||
| 70 | |||||||||||||
| 71 | engines: | ||||||||||||
| 72 | TemplateDeclare: | ||||||||||||
| 73 | dispatch_to: | ||||||||||||
| 74 | - A::Template::Class | ||||||||||||
| 75 | - Another::Template::Class | ||||||||||||
| 76 | |||||||||||||
| 77 | # in the app | ||||||||||||
| 78 | |||||||||||||
| 79 | get '/foo', sub { | ||||||||||||
| 80 | template 'foo' => { | ||||||||||||
| 81 | title => 'bar' | ||||||||||||
| 82 | }; | ||||||||||||
| 83 | }; | ||||||||||||
| 84 | |||||||||||||
| 85 | =head1 DESCRIPTION | ||||||||||||
| 86 | |||||||||||||
| 87 | This class is an interface between Dancer's template engine abstraction layer | ||||||||||||
| 88 | and the L<Template::Declare> templating system. | ||||||||||||
| 89 | |||||||||||||
| 90 | In order to use this engine, set the template to 'TemplateDeclare' in the configuration | ||||||||||||
| 91 | file: | ||||||||||||
| 92 | |||||||||||||
| 93 | template: TemplateDeclare | ||||||||||||
| 94 | |||||||||||||
| 95 | =head1 Template::Declare CONFIGURATION | ||||||||||||
| 96 | |||||||||||||
| 97 | Parameters can also be passed to the L<Template::Declare> interpreter via | ||||||||||||
| 98 | the configuration file, like so: | ||||||||||||
| 99 | |||||||||||||
| 100 | engines: | ||||||||||||
| 101 | TemplateDeclare: | ||||||||||||
| 102 | dispatch_to: | ||||||||||||
| 103 | - Some::Template | ||||||||||||
| 104 | - Some::Other::Template | ||||||||||||
| 105 | |||||||||||||
| 106 | All the dispatch classes are automatically | ||||||||||||
| 107 | loaded behind the scene. | ||||||||||||
| 108 | |||||||||||||
| 109 | =head1 USING LAYOUTS | ||||||||||||
| 110 | |||||||||||||
| 111 | If the layout is set to I<$name>, | ||||||||||||
| 112 | the template C</layout/$name> will be used and | ||||||||||||
| 113 | passed via the C<content> argument. | ||||||||||||
| 114 | |||||||||||||
| 115 | For example, a simple C<main> layout would be: | ||||||||||||
| 116 | |||||||||||||
| 117 | template '/layout/main' => sub { | ||||||||||||
| 118 | my ( $self, $args ) = @_; | ||||||||||||
| 119 | |||||||||||||
| 120 | html { | ||||||||||||
| 121 | body { | ||||||||||||
| 122 | outs_raw $args->{content} | ||||||||||||
| 123 | } | ||||||||||||
| 124 | } | ||||||||||||
| 125 | }; | ||||||||||||
| 126 | |||||||||||||
| 127 | =head1 SEE ALSO | ||||||||||||
| 128 | |||||||||||||
| 129 | L<Dancer>, L<Template::Declare>. | ||||||||||||
| 130 | |||||||||||||
| 131 | =head1 AUTHOR | ||||||||||||
| 132 | |||||||||||||
| 133 | Yanick Champoux | ||||||||||||
| 134 | |||||||||||||
| 135 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 136 | |||||||||||||
| 137 | This software is copyright (c) 2012 by Yanick Champoux. | ||||||||||||
| 138 | |||||||||||||
| 139 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 140 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 141 | |||||||||||||
| 142 | =cut | ||||||||||||
| 143 | |||||||||||||
| 144 | |||||||||||||
| 145 | __END__ | ||||||||||||