]> Dogcows Code - chaz/p5-CGI-Ex/blobdiff - lib/CGI/Ex/Template.pm
CGI::Ex 2.22
[chaz/p5-CGI-Ex] / lib / CGI / Ex / Template.pm
index 76cae387f68d0f7a8501bbadfe1336ff8fb4a784..c3acbbc7f9485bd7bb23d14c0dfab8e4b3a7833e 100644 (file)
 package CGI::Ex::Template;
 
+=head1 NAME
+
+CGI::Ex::Template - Template::Alloy based TT2/TT3/HT/HTE/Tmpl/Velocity engine.
+
+=cut
+
 use strict;
-use vars qw(@INCLUDE_PATH $CONTENT_SUBDIR);
-use base qw(Template);
+use warnings;
+use Template::Alloy 1.004;
+use base qw(Template::Alloy);
+use vars qw($VERSION
+            $QR_PRIVATE
+            $WHILE_MAX
+            $MAX_EVAL_RECURSE
+            $MAX_MACRO_RECURSE
+            $STAT_TTL
+            $EXTRA_COMPILE_EXT
+            $PERL_COMPILE_EXT
+            $SCALAR_OPS
+            $FILTER_OPS
+            $LIST_OPS
+            $HASH_OPS
+            $VOBJS
+            );
+
+$VERSION = '2.22';
+
+### install true symbol table aliases that can be localized
+*QR_PRIVATE        = *Template::Alloy::QR_PRIVATE;
+*WHILE_MAX         = *Template::Alloy::WHILE_MAX;
+*MAX_EVAL_RECURSE  = *Template::Alloy::MAX_EVAL_RECURSE;
+*MAX_MACRO_RECURSE = *Template::Alloy::MAX_MACRO_RECURSE;
+*STAT_TTL          = *Template::Alloy::STAT_TTL;
+*EXTRA_COMPILE_EXT = *Template::Alloy::EXTRA_COMPILE_EXT;
+*PERL_COMPILE_EXT  = *Template::Alloy::PERL_COMPILE_EXT;
+*SCALAR_OPS        = *Template::Alloy::SCALAR_OPS;
+*FILTER_OPS        = *Template::Alloy::FILTER_OPS;
+*LIST_OPS          = *Template::Alloy::LIST_OPS;
+*HASH_OPS          = *Template::Alloy::HASH_OPS;
+*VOBJS             = *Template::Alloy::VOBJS;
 
-use CGI::Ex;
-use CGI::Ex::Fill;
+1;
 
-$CONTENT_SUBDIR ||= 'content';
+__END__
 
-###----------------------------------------------------------------###
+=head1 SYNOPSIS
 
-sub new {
-  my $class = shift;
-  my $args  = ref($_[0]) ? shift : {@_};
+=head2 Template::Toolkit style usage
 
-  $args->{INCLUDE_PATH} ||= \@INCLUDE_PATH;
+    my $t = Template::Alloy->new(
+        INCLUDE_PATH => ['/path/to/templates'],
+    );
 
-  return $class->SUPER::new($args);
-}
+    my $swap = {
+        key1 => 'val1',
+        key2 => 'val2',
+        code => sub { 42 },
+        hash => {a => 'b'},
+    };
 
-sub process {
-  my $self = ref($_[0]) ? shift : shift->new;
-  my $in   = shift;
+    # print to STDOUT
+    $t->process('my/template.tt', $swap)
+        || die $t->error;
 
-  ### force the content to have a .html prefix
-  if (! ref $in) {
-    $in .= '.html' if $in !~ /\.\w+$/;
-  }
+    # process into a variable
+    my $out = '';
+    $t->process('my/template.tt', $swap, \$out);
 
-  ### prepend "content" dir as needed
-  if (! ref($in)                                # not a scalar ref or a file glob
-      && $in =~ m|^\w+(\.\w+)?(/\w+(\.\w+)?)*$| # not an absolute filename
-      && index($in, $CONTENT_SUBDIR) == -1) {
-    $in = $CONTENT_SUBDIR .'/'. $in;
-  }
+    ### Alloy uses the same syntax and configuration as Template::Toolkit
 
-  return $self->SUPER::process($in, @_);
-}
 
-###----------------------------------------------------------------###
+=head2 HTML::Template::Expr style usage
 
-sub out {
-  my $self = ref($_[0]) ? shift : shift->new;
-#  dex $self;
-  my $in   = shift;
-  my $form = shift;
-  my $fill = shift;
-  my $out  = '';
+    my $t = Template::Alloy->new(
+        filename => 'my/template.ht',
+        path     => ['/path/to/templates'],
+    );
 
-  ### run the template
-  my $status = $self->process($in, $form, \$out) || die $Template::ERROR;
+    my $swap = {
+        key1 => 'val1',
+        key2 => 'val2',
+        code => sub { 42 },
+        hash => {a => 'b'},
+    };
 
-  ### fill in any forms
-  &CGI::Ex::Fill::form_fill(\$out, $fill) if $fill && ! $self->{no_fill};
+    $t->param($swap);
 
-  return $out;
-}
+    # print to STDOUT (errors die)
+    $t->output(print_to => \*STDOUT);
 
-sub print {
-  my $self   = ref($_[0]) ? shift : shift->new;
-  my $in     = shift;
-  my $form   = shift;
-  my $fill   = shift || $form;
+    # process into a variable
+    my $out = $t->output;
 
-  &CGI::Ex::content_type();
-  print $self->out($in, $form, $fill);
-}
+    ### Alloy can also use the same syntax and configuration as HTML::Template
 
-###----------------------------------------------------------------###
+=head2 Text::Tmpl style usage
 
-1;
+    my $t = Template::Alloy->new;
 
-__END__
+    my $swap = {
+        key1 => 'val1',
+        key2 => 'val2',
+        code => sub { 42 },
+        hash => {a => 'b'},
+    };
 
-=head1 NAME
+    $t->set_delimiters('#[', ']#');
+    $t->set_strip(0);
+    $t->set_values($swap);
+    $t->set_dir('/path/to/templates');
 
-CGI::Ex::Template - Beginning interface to Templating systems - for they are many
+    my $out = $t->parse_file('my/template.tmpl');
 
-=head1 SYNOPSIS
+    my $str = "Foo #[echo $key1]# Bar";
+    my $out = $t->parse_string($str);
 
-  None yet.
+
+    ### Alloy uses the same syntax and configuration as Text::Tmpl
+
+=head2 Velocity (VTL) style usage
+
+    my $t = Template::Alloy->new;
+
+    my $swap = {
+        key1 => 'val1',
+        key2 => 'val2',
+        code => sub { 42 },
+        hash => {a => 'b'},
+    };
+
+    my $out = $t->merge('my/template.vtl', $swap);
+
+    my $str = "#set($foo 1 + 3) ($foo) ($bar) ($!baz)";
+    my $out = $t->merge(\$str, $swap);
 
 =head1 DESCRIPTION
 
-=head1 AUTHORS
+CGI::Ex::Template is the original base for the code that is now
+Template::Alloy.  Template::Alloy employed enough complexity and
+featureset to warrant moving it out to a separate namespace.
 
-Paul Seamons <perlspam at seamons dot com>
+CGI::Ex::Template is now a place holder subclass of Template::Alloy.
+You can use CGI::Ex::Template as a standalone module - but it is
+suggested that you use Template::Alloy directly instead.
 
-=cut
+For examples of usage, configuration, syntax, bugs, vmethods,
+directives, etc please refer to the L<Template::Alloy> documentation.
+
+=head1 LICENSE
+
+This module may be distributed under the same terms as Perl itself.
 
+=head1 AUTHOR
+
+Paul Seamons <perl at seamons dot com>
+
+=cut
This page took 0.031701 seconds and 4 git commands to generate.