CGI-Application-Plugin-AnyTemplate
view release on metacpan or search on metacpan
lib/CGI/Application/Plugin/AnyTemplate/Base.pm view on Meta::CPAN
package CGI::Application::Plugin::AnyTemplate::Base;
=head1 NAME
CGI::Application::Plugin::AnyTemplate::Base - Base class for templates
=head1 DESCRIPTION
This documentation is mainly for developers who want to write additional
Template drivers. For how to use the system, see the docs for
L<CGI::Application::Plugin::AnyTemplate>
=cut
use strict;
use Carp;
use Scalar::Util qw(weaken);
sub _new {
my $proto = shift;
my $class = ref $proto || $proto;
my %args = @_;
my $self = {};
$self->{'driver_config'} = delete $args{'driver_config'} || {};
$self->{'native_config'} = delete $args{'native_config'} || {};
$self->{'include_paths'} = delete $args{'include_paths'} || [];
$self->{'filename'} = delete $args{'filename'};
$self->{'string_ref'} = delete $args{'string_ref'};
$self->{'callers_package'} = delete $args{'callers_package'};
$self->{'return_references'} = delete $args{'return_references'};
$self->{'conf_name'} = delete $args{'conf_name'};
$self->{'webapp'} = delete $args{'webapp'};
$self->{'component_handler_class'} = delete $args{'component_handler_class'}
|| 'CGI::Application::Plugin::AnyTemplate::ComponentHandler';
bless $self, $class;
weaken $self->{'webapp'};
$self->initialize;
return $self;
}
=head1 METHODS
=over 4
=item param
The C<param> method gets and sets values within the template.
my $template = $self->template->load;
my @param_names = $template->param();
my $value = $template->param('name');
$template->param('name' => 'value');
$template->param(
'name1' => 'value1',
'name2' => 'value2'
);
It is designed to behave similarly to the C<param> method in other modules like
C<CGI> and C<HTML::Template>.
=cut
sub param {
my $self = shift;
if (@_) {
my $param;
if (ref $_[0] eq 'HASH') {
$param = shift;
}
elsif (@_ == 1) {
return $self->{'param'}{$_[0]};
}
else {
$param = { @_ };
}
$self->{'param'} ||= {};
$self->{'param'}{$_} = $param->{$_} for keys %$param;
}
else {
$self->{'param'} ||= {};
return keys %{ $self->{'param'} };
}
}
=item get_param_hash
Returns the template variables as a hash of names and values.
my %params = $template->get_param_hash;
( run in 0.577 second using v1.01-cache-2.11-cpan-39bf76dae61 )