| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Template::TAL::Template - a TAL template | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | my $template = Template::TAL::Template->new->source( "<html>...</html>" ); | ||
| 8 | my $dom = $template->process( {} ); | ||
| 9 | print $dom->toString(); | ||
| 10 | |||
| 11 | =head1 DESCRIPTION | ||
| 12 | |||
| 13 | This class represents a single TAL template, and stores its XML source. | ||
| 14 | You'll probably not see these objects directly - Template::TAL takes template | ||
| 15 | names and returns bytes. But you might. | ||
| 16 | |||
| 17 | =cut | ||
| 18 | |||
| 19 | package Template::TAL::Template; | ||
| 20 | use warnings; | ||
| 21 | use strict; | ||
| 22 | use Carp qw( croak ); | ||
| 23 | use XML::LibXML; | ||
| 24 | |||
| 25 | =head1 METHODS | ||
| 26 | |||
| 27 | =over | ||
| 28 | |||
| 29 | =item new() | ||
| 30 | |||
| 31 | Create a new TAL template object. | ||
| 32 | |||
| 33 | =cut | ||
| 34 | |||
| 35 | sub new { | ||
| 36 | my $class = shift; | ||
| 37 | my $self = bless {}, $class; | ||
| 38 | return $self; | ||
| 39 | } | ||
| 40 | |||
| 41 | =item filename( set filename ) | ||
| 42 | |||
| 43 | the filename of the template, an alternative to L<source> below. | ||
| 44 | |||
| 45 | =cut | ||
| 46 | |||
| 47 | sub filename { | ||
| 48 | my $self = shift; | ||
| 49 | my $parser = XML::LibXML->new(); | ||
| 50 | return $self->document( $parser->parse_file( shift ) ); | ||
| 51 | } | ||
| 52 | |||
| 53 | =item source( set source ) | ||
| 54 | |||
| 55 | the TAL source of this template, as a scalar | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||
| 59 | sub source { | ||
| 60 | my $self = shift; | ||
| 61 | my $parser = XML::LibXML->new(); | ||
| 62 | return $self->document( $parser->parse_string( shift ) ); | ||
| 63 | } | ||
| 64 | |||
| 65 | =item document( [document] ) | ||
| 66 | |||
| 67 | returns the XML::LibXML::Document object that represents this | ||
| 68 | template, or sets it if a parameter is given. | ||
| 69 | |||
| 70 | =cut | ||
| 71 | |||
| 72 | sub document { | ||
| 73 | my $self = shift; | ||
| 74 | return $self->{_document} unless @_; | ||
| 75 | $self->{_document} = shift; | ||
| 76 | return $self; | ||
| 77 | } | ||
| 78 | |||
| 79 | =back | ||
| 80 | |||
| 81 | =head1 COPYRIGHT | ||
| 82 | |||
| 83 | Written by Tom Insam, Copyright 2005 Fotango Ltd. All Rights Reserved | ||
| 84 | |||
| 85 | This program is free software; you can redistribute | ||
| 86 | it and/or modify it under the same terms as Perl itself. | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | 1; |