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   1722 use strict;
  6         9  
  6         141  
4 6     6   23 use warnings;
  6         7  
  6         154  
5              
6 6     6   22 use Moose::Role;
  6         7  
  6         49  
7 6     6   13485 use namespace::autoclean;
  6         13  
  6         44  
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   1724 use Template;
  6         74160  
  6         130  
47 6     6   32 use Carp;
  6         7  
  6         981  
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;
88