diff options
-rw-r--r-- | lib/OX/View/TT.pm | 102 |
1 files changed, 79 insertions, 23 deletions
diff --git a/lib/OX/View/TT.pm b/lib/OX/View/TT.pm index 7fc3f0d..5e11579 100644 --- a/lib/OX/View/TT.pm +++ b/lib/OX/View/TT.pm @@ -1,9 +1,47 @@ package OX::View::TT; use Moose; +# ABSTRACT: View wrapper class for TT renderers use MooseX::Types::Path::Class; use Template; +=head1 SYNOPSIS + + package MyApp; + use OX; + + has view => ( + is => 'ro', + isa => 'OX::View::TT', + dependencies => ['template_root'], + ); + +=head1 DESCRIPTION + +This is a very thin wrapper around L<Template> which exposes some OX +functionality to your template files. Templates rendered with this class will +have access to these additional variables: + +=over 4 + +=item C<base> + +The base URL that this app is hosted at (C<SCRIPT_NAME>). + +=item C<uri_for> + +A function which forwards its arguments to the C<uri_for> method in +L<OX::Request>. + +=item C<m> + +The hashref of match variables for the current route (equivalent to the +C<mapping> method on the L<OX::Request> object). + +=back + +=cut + has 'template_root' => ( is => 'ro', isa => 'Path::Class::Dir', @@ -41,6 +79,14 @@ sub _build_template_params { } } +=method C<< render($r, $template, $params) >> + +Renders a template, and returns a string containing the contents. C<$r> is the +request object, C<$template> is the name of the template, and C<$params> are +extra variables to pass to the template. + +=cut + sub render { my ($self, $r, $template, $params) = @_; my $out = ''; @@ -52,6 +98,16 @@ sub render { $out; } +=method C<< template($r) >> + +This is an action method which can be used directly as a route endpoint: + + route '/about' => 'view.template', ( + template => 'about.tt', + ); + +=cut + sub template { my $self = shift; my ($r) = @_; @@ -64,48 +120,48 @@ sub template { } __PACKAGE__->meta->make_immutable; +no Moose; -no Moose; 1; +=head1 BUGS -__END__ +No known bugs. -=pod +Please report any bugs through RT: email +C<bug-ox-view-tt at rt.cpan.org>, or browse to +L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=OX-View-TT>. -=head1 NAME +=head1 SEE ALSO -OX::View::TT - A Moosey solution to this problem +L<OX> -=head1 SYNOPSIS +=head1 SUPPORT - use OX::View::TT; +You can find this documentation for this module with the perldoc command. -=head1 DESCRIPTION + perldoc OX::View::TT -=head1 METHODS +You can also look for information at: =over 4 -=item B<> +=item * AnnoCPAN: Annotated CPAN documentation -=back +L<http://annocpan.org/dist/OX-View-TT> -=head1 BUGS - -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. +=item * CPAN Ratings -=head1 AUTHOR +L<http://cpanratings.perl.org/d/OX-View-TT> -Stevan Little E<lt>stevan.little@iinteractive.comE<gt> +=item * RT: CPAN's request tracker -=head1 COPYRIGHT AND LICENSE +L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=OX-View-TT> -Copyright 2009 Infinity Interactive, Inc. +=item * Search CPAN -L<http://www.iinteractive.com> +L<http://search.cpan.org/dist/OX-View-TT> -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. +=back =cut + +1; |