blib/lib/Tatsumaki/Template/Markapl.pm

filter: Statementstmt 74.1% 23 / 31 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 58.3% 7 / 12 Podpod 0.0% 0 / 2 totaltotal 66.6% 30 / 45 CC 1 SCAR 3.5
CC
1
Cov
74%
_build_view_class
2.0
render_file
2.0
__ANON__
2.0
CRAP 1.4
↑ Summary
1 # ABSTRACT: Use Markapl as Tatsumaki's template system.
2  
3 package Tatsumaki::Template::Markapl;
4 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 $Tatsumaki::Template::Markapl::VERSION = '0.3';
6 }
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Tatsumaki::Template::Markapl - Use Markapl as L<Tatsumaki>'s template system.
13  
14 =head1 VERSION
15  
16 version 0.3
17  
18 =head1 DESCRIPTION
19  
20 This module will use L<Markapl> as L<Tatsumaki>'s template system.
21  
22 L<Tatsumaki> do not support custom template engine currently, so we use L<Sub::Install> to rewrite L<Template::Application::_build_template>.
23  
24 =head1 SYNOPSIS
25  
26 # This usually is in app.psgi
27 use Tatsumaki::Template::Markapl;
28  
29 # Install the template system
30 Tatsumaki::Template::Markapl->rewrite('MyProj::View');
31  
32 And then in C<MyProj::View>:
33  
34 # MyProj::View
35 package MyProj::View;
36 use Markapl;
37  
38 template '/' => sub {
39 my $self = shift;
40  
41 html {
42 head {
43 title { 'My Title' };
44 };
45  
46 body {
47 div('#bd') {
48 outs('Hello, ');
49 outs($self->get('name'));
50 };
51 };
52 };
53 };
54  
55 Now you can use it in handler:
56  
57 # MyProj::Handler::Index
58 package MyProj::Handler::Index;
59 use parent 'Tatsumaki::Handler';
60  
61 sub get {
62 shift->render('/', {name => 'perl'});
63 };
64  
65 =cut
66  
67 1 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 1 extends 'Tatsumaki::Template';
69  
70 1 has 'view_class_name' => (is => 'rw');
71 1 has 'view_class' => (is => 'rw', lazy_build => 1);
72  
73 1 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 1 ▶use Sub::Install;
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 0 ▶sub _build_view_class {
Subroutine _build_view_class: not called CC=1 SCAR=6.9
77 0 Plack::Util::load_class(shift->view_class_name);
78 }
79  
80 0 ▶sub render_file {
Subroutine render_file: not called CC=1 SCAR=6.9
Pod undocumented
81 0 my $self = shift;
82  
83 0 my $str = $self->view_class->render(@_);
84 0 ▶ Plack::Util::inline_object(as_string => sub { $str });
Subroutine __ANON__: not called CC=1 SCAR=6.9
85 };
86  
87 0 ▶sub rewrite {
Subroutine rewrite: not called CC=1 SCAR=6.9
Pod undocumented
88 0 my ($self, $view_class_name) = @_;
89  
90 Sub::Install::reinstall_sub({
91 0 ▶ code => sub { Tatsumaki::Template::Markapl->new(view_class_name => $view_class_name); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 0 into => 'Tatsumaki::Application',
93 as => '_build_template',
94 });
95 }
96  
97 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
98  
99 =head1 AUTHOR
100  
101 Gea-Suan Lin, C<< <gslin at gslin.org> >>
102  
103 =head1 LICENSE AND COPYRIGHT
104  
105 Copyright 2011 Gea-Suan Lin.
106  
107 This software is released under 3-clause BSD license. See
108 L<http://www.opensource.org/licenses/bsd-license.php> for more
109 information.
110  
111 =cut
112  
113 1 1;
↑ Summary