File Coverage

blib/lib/Perlanet/Trait/TemplateToolkit.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1             package Perlanet::Trait::TemplateToolkit;
2              
3 6     6   3677 use strict;
  6         16  
  6         205  
4 6     6   42 use warnings;
  6         18  
  6         215  
5              
6 6     6   41 use Moose::Role;
  6         16  
  6         58  
7 6     6   35741 use namespace::autoclean;
  6         18  
  6         73  
8              
9             =head1 NAME
10              
11             Perlanet::Trait::TemplateToolkit - render the feed via a Template Toolkit
12             template
13              
14             =head1 SYNOPSIS
15              
16             my $perlanet = Perlanet->new_with_traits(
17             traits => [ 'Perlanet::Trait::TemplateToolkit' ]
18             );
19              
20             $perlanet->run;
21              
22             =head1 DESCRIPTION
23              
24             Renders the aggregated set of feeds via a Template Toolkit template.
25              
26             =head1 ATTRIBUTES
27              
28             =head2 template_input
29              
30             The Template Toolkit template to use as input
31              
32             =head2 template_output
33              
34             The path to save the resulting output to
35              
36             =head1 TEMPLATE TOOLKIT STASH
37              
38             The following are exported into your template:
39              
40             =head2 feed
41              
42             A L<Perlanet::Feed> that represents the aggregation of all posts
43              
44             =cut
45              
46 6     6   3924 use Template;
  6         89966  
  6         201  
47 6     6   59 use Carp;
  6         17  
  6         1028  
48              
49             has 'page' => (
50             isa => 'HashRef',
51             is => 'rw',
52             default => sub {
53             { file => 'index.html', template => 'index.tt' }
54             },
55             );
56              
57             after 'render' => sub {
58             my ($self, $feed) = @_;
59             my $tt = Template->new;
60             $tt->process(
61             $self->page->{template},
62             {
63             feed => $feed,
64             cfg => $self,
65             },
66             $self->page->{file},
67             {
68             binmode => ':utf8'
69             }
70             ) or croak $tt->error;
71             };
72              
73             =head1 AUTHOR
74              
75             Oliver Charles, <oliver.g.charles@googlemail.com>
76              
77             =head1 COPYRIGHT AND LICENSE
78              
79             Copyright (c) 2010 by Magnum Solutions Ltd.
80              
81             This library is free software; you can redistribute it and/or modify
82             it under the same terms as Perl itself, either Perl version 5.10.0 or,
83             at your option, any later version of Perl 5 you may have available.
84              
85             =cut
86              
87             1;