line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::Template::Mason2; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
BEGIN { |
4
|
2
|
|
|
2
|
|
18439
|
$Dancer2::Template::Mason2::VERSION = '0.01'; |
5
|
|
|
|
|
|
|
} |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
472
|
use Moo; |
|
2
|
|
|
|
|
11707
|
|
|
2
|
|
|
|
|
18
|
|
8
|
2
|
|
|
2
|
|
2055
|
use Carp qw( croak ); |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
1299
|
|
9
|
2
|
|
|
2
|
|
508
|
use Dancer2::Core::Types; |
|
2
|
|
|
|
|
7400
|
|
|
2
|
|
|
|
|
870
|
|
10
|
2
|
|
|
2
|
|
2696
|
use Mason; |
|
2
|
|
|
|
|
3009337
|
|
|
2
|
|
|
|
|
566
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Dancer2::Core::Role::Template'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has '+engine' => ( isa => InstanceOf ['Mason::Interp'], ); |
15
|
|
|
|
|
|
|
has '+default_tmpl_ext' => ( default => sub { 'mc' } ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _build_engine { |
18
|
1
|
|
|
1
|
|
736
|
my ( $self ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
11
|
my %config = ( |
21
|
|
|
|
|
|
|
autoextend_request_path => 0, |
22
|
1
|
|
|
|
|
2
|
%{ $self->config }, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
33
|
|
|
11
|
$config{'comp_root'} ||= $self->views; |
26
|
1
|
|
33
|
|
|
48
|
$config{'data_dir'} ||= $self->settings->{'appdir'}; |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
50
|
return Mason->new( %config ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub render { |
32
|
3
|
|
|
3
|
0
|
167155
|
my ( $self, $template, $tokens ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
18
|
my $root_dir = $self->views; |
35
|
3
|
|
|
|
|
162
|
$template =~ s/^\Q$root_dir//; # cut the leading path |
36
|
3
|
|
|
|
|
11
|
$template =~ y|\\|/|; # convert slashes on Windows |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
66
|
my $content = $self->engine->run( $template, %$tokens )->output; |
39
|
3
|
|
|
|
|
488711
|
return $content; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__END__ |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=encoding utf-8 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Dancer2::Template::Mason2 - Mason 2.x engine for Dancer2 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 VERSION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
version 0.01 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SYNOPSIS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
In C<config.yml> |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
template: "mason2" |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
In C<MyApp.pm> |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
get '/foo' => sub { |
65
|
|
|
|
|
|
|
template foo => { |
66
|
|
|
|
|
|
|
title => 'bar', |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
In C<views/foo.mc> |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
<%args> |
73
|
|
|
|
|
|
|
$.title |
74
|
|
|
|
|
|
|
</%args> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
<h1><% $.title %></h1> |
77
|
|
|
|
|
|
|
<p>Hello World!</p> |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Dancer2::Template::Mason2 is a template engine that allows you |
82
|
|
|
|
|
|
|
to use L<Mason 2.x|Mason> with L<Dancer2>. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
In order to use this engine, set the template to 'mason2' in |
85
|
|
|
|
|
|
|
the Dancer2 configuration file: |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
template: "mason2" |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
The default template extension is '.mc'. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 CONFIGURATION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Paramters can also be passed to C<< Mason->new() >> via the |
94
|
|
|
|
|
|
|
configuration file like so: |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
engines: |
97
|
|
|
|
|
|
|
mason2: |
98
|
|
|
|
|
|
|
data_dir: /path/to/data_dir |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
C<comp_root> defaults to the C<views> configuration setting or, |
101
|
|
|
|
|
|
|
if it is undefined, to the C</views> subdirectory of the application. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
C<data_dir> defaults to C</data> subdirectory in the project root |
104
|
|
|
|
|
|
|
directory. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SEE ALSO |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
L<Dancer2>, L<Mason> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AUTHOR |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
David Betz E<lt>hashref@gmail.comE<gt> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 LICENSE |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Copyright (C) David Betz. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
119
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |