Eve
view release on metacpan or search on metacpan
lib/Eve/HttpResource/Template.pm view on Meta::CPAN
text_var_hash => $text_var_hash);
$dispatcher->bind(
name => 'some_unique_name',
pattern => '/some_uri',
base_uri => $some_base_uri,
resource_constructor => sub {
return $resource;
});
=head1 DESCRIPTION
B<Eve::HttpResource::Template> is a simple HTTP resource that only
displays a parsed template. All the templates have the following
objects available in their scope:
=over 4
=item C<session>
an instance of the B<Eve::Session> object for the current user,
=back
=head3 Constructor arguments
=over 4
=item C<response>
an HTTP response object,
=item C<session_constructor>
a reference to a subroutine that returns a session object,
=item C<dispatcher>
an HTTP dispatcher object,
=item C<template>
a template object,
=item C<template_file>
a template file name,
=item C<template_var_hash>
(optional) a hash of variables to be passed to the processed template,
defaults to an empty hash,
=item C<require_auth>
(optional) if a user is not authenticated, throw a
C<Eve::Exception::Http::401Unauthorized>,
=item C<content_type>
(optional) response content-type, defaults to C<text/html>,
=item C<charset>
(optional) response character set, defaults to C<UTF-8>.
=back
=head1 METHODS
=head2 B<init()>
=cut
sub init {
my ($self, %arg_hash) = @_;
my $arg_hash = Eve::Support::arguments(\%arg_hash,
my ($template, $template_file),
my (
$template_var_hash,
$require_auth,
$content_type,
$charset) =
({}, \undef, 'text/html', \undef));
$self->{'_template'} = $template;
$self->{'_template_file'} = $template_file;
$self->{'_template_var_hash'} = $template_var_hash;
$self->{'_require_auth'} = $require_auth;
$self->{'_content_type'} = $content_type;
$self->{'_charset'} = $charset;
$self->SUPER::init(%{$arg_hash});
return;
}
sub _get {
my ($self, %matches_hash) = @_;
my $account_id = $self->_session->get_parameter(name => 'account_id');
if ($self->_require_auth and not defined $account_id) {
Eve::Exception::Http::401Unauthorized->throw();
}
my $output = $self->_template->process(
file => $self->_template_file,
var_hash => {
%{$self->_template_var_hash},
'session' => $self->_session,
'dispatcher' => $self->_dispatcher,
'request' => $self->_request,
'matches_hash' => \%matches_hash});
if (defined $self->_content_type) {
$self->_response->set_header(
name => 'Content-type',
value => $self->_content_type);
}
if (defined $self->_charset) {
( run in 0.577 second using v1.01-cache-2.11-cpan-524268b4103 )