Ian Sillitoe > MooseX-Templated-0.03 > MooseX::Templated::View

Download:
MooseX-Templated-0.03.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source  

NAME ^

MooseX::Templated::View - Interface for MooseX::Templated views

SYNOPSIS ^

    package MooseX::Templated::View::SomeRenderer;
    
    use Moose;
    use Some::Renderer;
    
    with 'MooseX::Templated::View';
    
    # engine class
    has '+engine_class'     => ( default => 'Some::Renderer' );

    # default config to pass to engine constructor
    has '+engine_config'    => ( default => sub { { OPTION => 1 } } );

    # default file extension to use
    has '+template_src_ext' => ( default => '.ext' );
    
    # return rendered output as string
    sub process {
        my $self        = shift;

        # instantiated from engine_class and engine_config
        my $engine      = $self->engine; 

        # source set by framework defaults
        my $source      = $self->source;
        
        # implemented by engine
        my $output = $engine->some_render_method( 
                        src   => $source, 
                        stash => { self => $self },
                    );

        return $output;
    }

/path/to/Farm/Chicken.pm

    package Farm::Chicken;
    use Moose;
    with 'MooseX::Templated::Role';

    has 'feathers' => ( is => 'rw' );

/path/to/Farm/Chicken.ext

    This chicken has <<self.feathers>> feathers

Elsewhere...

    $chicken = Farm::Chicken->new( 
            feathers             => 57,
            template_view_class  => 'MooseX::Templated::View::SomeRenderer',
        );

    $chicken->render(); # This chicken has 57 feathers

ATTRIBUTES ^

engine

Instance of the templating engine used for the render

engine_class <required>

The class name of template engine object

This is used to instantiate the new

engine_config( \%options )

Configuration options to pass to the Template engine constructor

module <required>

This is a reference to the object we are rendering - i.e. the object consuming the MooseX::Templated::Role

source

This is the template source string

template_src_base

Where to start looking for associated template files. If this evaluates to false then it will assume the template file resides alongside the module (with a different extension depending on the particular view).

  Farm::Cow.pm

  template_src_base => ''               # /usr/lib/perl5/[...]/Farm/Cow.tt
  template_src_base => '/etc/tt2/src'   # /etc/tt2/src/Farm/Cow.tt

template_src_ext

Extension to use when searching for the template_src, e.g. '.tt'

INTERFACE ^

render( \%options )

This sets up the generic environment for the render (e.g. template source and stash vars) then calls the process method on the implementing view.

options

source

Sets the template source to something other than the default

See source

stash

Provides additional key/value data to be available in the template source

process

The individual view implements this method to actually process the template.

set_source( $shortcut | $filename | \"raw template source" )

Template source code used to process the template - will return the first successful step from the following:

source => SCALAR

1. Internal method shortcut
2. External file shortcut
3. File path

e.g. for MooseX::Templated::View::TT

    source => ''    # Farm::Cow::_template()
                    # /path/to/Farm/Cow.tt
    
    source => 'XML' # Farm::Cow::_template_xml()
                    # /path/to/Farm/Cow.xml.tt

    source => 'file.tt'

SCALAR REF

Raw template source string
    source => \'[% self.blah %]'

build_src_path( \%options )

Builds the default filename to be used the template source

    Farm::Cow => /path/to/Farm/Cow.tt
    
    template_src_base  class_name    template_src_ext
    /path/to/          Farm/Cow      .tt

options

Explicitly passed options override defaults

'base' => '/alt/path'
'ext' => '.ext'

DESCRIPTION ^

This is an interface that allows the front-end MooseX::Templated::Role to speak to the specific back-end template engines (e.g. MooseX::Templated::View::TT). It also provides generic functionality for all MooseX::Templated::View:: modules.

DEPENDENCIES ^

Readonly, File::Slurp, File::Where, Path::Class::File

INCOMPATIBILITIES ^

None reported.

BUGS AND LIMITATIONS ^

No bugs have been reported.

Please report any bugs or feature requests to bug-moosex-templated@rt.cpan.org, or through the web interface at http://rt.cpan.org.

ACKNOWLEDGEMENTS ^

Chris Prather (perigrin)

AUTHOR ^

Ian Sillitoe <isillitoe@cpan.org>

LICENCE AND COPYRIGHT ^

Copyright (c) 2008, Ian Sillitoe <isillitoe@cpan.org>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

syntax highlighting: