blib/lib/Dancer/Template/Mason2.pm

filter: Statementstmt 97.2% 35 / 36 Branchbran 50.0% 1 / 2 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.9% 10 / 11 Podpod 100% 3 / 3 totaltotal 81.5% 53 / 65 CC 6 SCAR 12.6
CC
6
Cov
85%
init
7.6
default_tmpl_ext
2.0
BEGIN
1.0
CRAP 3.5
↑ Summary
1 package Dancer::Template::Mason2;
2 BEGIN {
3 2 ▶ $Dancer::Template::Mason2::VERSION = '0.04';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 2 ▶use Dancer::Config 'setting';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Mason;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use base 'Dancer::Template::Abstract';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 my $_engine;
14 my $root_dir;
15  
16 sub init {
17 1 ▶ my $self = shift;
Subroutine init: called CC=6 SCAR=20.3
Pod documented
18 1 ▶ my $config = $self->config || {};
Condition50%1/2
$self->config || {}
l!l
10
MC/DC0%0/1
$self->config || {}
$self->config
Truth table50%1/2
A
A= $self->config
Aresult
11
00
19  
20 1 ▶ $root_dir = $config->{comp_root} ||= setting('views') || $FindBin::Bin . '/views';
Condition40%2/5
$config->{"comp_root"} ||= setting("views") || $FindBin::Bin . '/views'
l!l&&r!l&&!r
010
setting('views') || $FindBin::Bin . '/views'
l!l
01
MC/DC0%0/2
$config->{"comp_root"} ||= setting("views") || $FindBin::Bin . '/views'
$config->{"comp_root"} setting('views')
Truth table0%0/3
A ||= B
A= $config->{"comp_root"}B= setting('views')
ABresult
1X1
011
000
21 1 ▶ $config->{data_dir} ||= dirname($root_dir) . "/data";
Condition50%1/2
$config->{"data_dir"} ||= dirname($root_dir) . '/data'
l!l
01
MC/DC0%0/1
$config->{"data_dir"} ||= dirname($root_dir) . '/data'
$config->{"data_dir"}
Truth table50%1/2
A
A= $config->{"data_dir"}
Aresult
11
00
22 1 ▶ $config->{autoextend_request_path} = 0 if !exists( $config->{autoextend_request_path} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $config->{"autoextend_request_path"} 1 0 1
23  
24 1 $_engine = Mason->new(%$config);
25 }
26  
27 0 ▶sub default_tmpl_ext { "mc" }
Subroutine default_tmpl_ext: not called CC=1 SCAR=6.9
Pod documented
28  
29 sub render {
30 1 ▶ my ( $self, $template, $tokens ) = @_;
Subroutine render: called CC=1 SCAR=0.0
Pod documented
31  
32 1 $template =~ s/^\Q$root_dir//; # cut the leading path
33 1 $template =~ y|\\|/|; # convert slashes on Windows
34  
35 1 my $content = $_engine->run( $template, %$tokens )->output;
36 1 return $content;
37 }
38  
39 2 1;
40  
41  
42 __END__
43 =pod
44  
45 =head1 NAME
46  
47 Dancer::Template::Mason2 - Mason 2.x wrapper for Dancer
48  
49 =head1 VERSION
50  
51 version 0.04
52  
53 =head1 SYNOPSIS
54  
55 # in 'config.yml'
56 template: 'mason2'
57  
58 # in the app
59
60 get '/foo', sub {
61 template 'foo' => {
62 title => 'bar'
63 };
64 };
65  
66 Then, in C<views/foo.mc>:
67  
68 <%args>
69 $.title
70 </%args>
71  
72 <h1><% $.title %></h1>
73  
74 <p>Mason says hi!</p>
75  
76 =head1 DESCRIPTION
77  
78 This class is an interface between Dancer's template engine abstraction layer
79 and the L<Mason 2.x|Mason> templating system.
80  
81 In order to use this engine, set the template to 'mason2' in the configuration
82 file:
83  
84 template: mason2
85  
86 The default template extension is ".mc".
87  
88 =head1 CONFIGURATION
89  
90 Parameters can also be passed to C<< Mason->new >> via the configuration file,
91 like so:
92  
93 engines:
94 mason2:
95 data_dir: /path/to/data_dir
96  
97 C<comp_root>, if not specified, defaults to the C<views> configuration setting
98 or, if it's undefined, to the C</views> subdirectory of the application.
99  
100 C<data_dir>, if not specified, defaults to a C</data> subdirectory alongside
101 the C<comp_root>.
102  
103 =head1 SEE ALSO
104  
105 L<Dancer>, L<Mason>, L<Dancer::Template::Mason>
106  
107 =head1 AUTHOR
108  
109 Jonathan Swartz <swartz@pobox.com>
110  
111 =head1 COPYRIGHT AND LICENSE
112  
113 This software is copyright (c) 2011 by Jonathan Swartz.
114  
115 This is free software; you can redistribute it and/or modify it under
116 the same terms as the Perl 5 programming language system itself.
117  
118 =cut
119  
↑ Summary