| 1 | package MooseX::Templated::View; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | MooseX::Templated::View - Interface for MooseX::Templated views | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | package MooseX::Templated::View::MyRenderer; | ||
| 10 | |||
| 11 | use Moose; | ||
| 12 | use My::Renderer; | ||
| 13 | |||
| 14 | with 'MooseX::Templated::View'; | ||
| 15 | |||
| 16 | my %CONFIG = ( FOO => 1 ); | ||
| 17 | |||
| 18 | sub build_default_template_suffix { '.tpl' } | ||
| 19 | sub build_renderer { My::Renderer->new( option => 1 ) } | ||
| 20 | |||
| 21 | # return rendered output as string | ||
| 22 | sub process { | ||
| 23 | my $self = shift; | ||
| 24 | |||
| 25 | # instantiated from view_class and view_config | ||
| 26 | my $view = $self->view; | ||
| 27 | |||
| 28 | # source will be provided by defaults | ||
| 29 | my $source = $self->source; | ||
| 30 | |||
| 31 | # get rendered output from backend | ||
| 32 | my $output = $engine->some_render_method( | ||
| 33 | src => $source, | ||
| 34 | stash => { self => $self }, | ||
| 35 | ); | ||
| 36 | |||
| 37 | return $output; | ||
| 38 | } | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | 4 | ▶ | use Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 43 | 4 | ▶ | use Moose::Util::TypeConstraints; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 44 | 4 | ▶ | use MooseX::Types::Path::Class qw/ Dir /; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 45 | 4 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 46 | 4 | ▶ | use Path::Class; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 47 | 4 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 48 | |||
| 49 | 4 | subtype 'TemplateSource' | |
| 50 | => as 'Str'; | ||
| 51 | |||
| 52 | 4 | requires qw/ | |
| 53 | build_default_template_suffix | ||
| 54 | build_renderer | ||
| 55 | /; | ||
| 56 | |||
| 57 | 4 | has default_template_suffix => ( | |
| 58 | isa => 'Str', | ||
| 59 | is => 'ro', | ||
| 60 | builder => 'build_default_template_suffix', | ||
| 61 | ); | ||
| 62 | |||
| 63 | 4 | has 'renderer' => ( | |
| 64 | isa => 'Object', | ||
| 65 | is => 'ro', | ||
| 66 | lazy => 1, | ||
| 67 | builder => 'build_renderer', | ||
| 68 | ); | ||
| 69 | |||
| 70 | =head1 INTERFACE | ||
| 71 | |||
| 72 | =head2 process( $source, $model_object ) | ||
| 73 | |||
| 74 | The individual view needs to implement this method to actually process the template. | ||
| 75 | |||
| 76 | =cut | ||
| 77 | |||
| 78 | 4 | requires 'process'; | |
| 79 | |||
| 80 | 4 | 1; | |
| 81 | __END__ | ||