File: TemplateToolkit.pm

package info (click to toggle)
libperlanet-perl 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 444 kB
  • sloc: xml: 1,177; perl: 757; sh: 6; makefile: 5
file content (90 lines) | stat: -rw-r--r-- 1,634 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package Perlanet::Trait::TemplateToolkit;

use 5.10.0;
use strict;
use warnings;

use Moose::Role;
use namespace::autoclean;

=head1 NAME

Perlanet::Trait::TemplateToolkit - render the feed via a Template Toolkit
template

=head1 SYNOPSIS

   my $perlanet = Perlanet->new_with_traits(
     traits => [ 'Perlanet::Trait::TemplateToolkit' ]
   );

   $perlanet->run;

=head1 DESCRIPTION

Renders the aggregated set of feeds via a Template Toolkit template.

=head1 ATTRIBUTES

=head2 template_input

The Template Toolkit template to use as input

=head2 template_output

The path to save the resulting output to

=head1 TEMPLATE TOOLKIT STASH

The following are exported into your template:

=head2 feed

A L<Perlanet::Feed> that represents the aggregation of all posts

=cut

use Template;
use Carp;

has 'page' => (
  isa       => 'HashRef',
  is        => 'rw',
  default   => sub {
    { file => 'index.html', template => 'index.tt' };
  },
);

after 'render' => sub {
  my $self = shift;
  my ($feed) = @_;
  my $tt = Template->new;
  $tt->process(
    $self->page->{template},
    {
      feed   => $feed,
      cfg    => $self, # deprecated
      config => $self->config,
    },
    $self->page->{file},
    {
      binmode => ':utf8'
    }
  ) or croak $tt->error;
};

=head1 AUTHOR

Oliver Charles, <oliver.g.charles@googlemail.com>

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2010 by Magnum Solutions Ltd.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.

=cut

1;