ClearPress::view - MVC view superclass
$Revision: 470 $
my $oView = ClearPress::view::<subclass>->new({util => $oUtil}); $oView->model($oModel); print $oView->decor? $oDecorator->header : q[Content-type: ].$oView->content_type."\n\n"; print $oView->render; print $oView->decor?$oDecorator->footer:q[];
View superclass for the ClearPress framework
my $oView = ClearPress::view::<subclass>->new({util => $oUtil, ...});
Defaults are: { '*' => [Gettext => sprintf q[%s/po/*.po], $util->data_path], 'en' => ['Auto'], }
sets the aspect based on the HTTP Accept: header - useful for API access setting Accept: text/xml
my $sTemplateName = $oView->template_name; $oView->template_name($sOverriddenName);
my $sMethodName = $oView->method_name;
$oView->add_warning($sWarningMessage);
my $arWarningStrings = $oView->warnings;
This should usually take into account $self->action which suggests read or write access. my $bIsAuthorised = $oView->authorised;
my $sViewOutput = $oView->render;
Implemented in subclass: sub streamed_aspects { return [qw(list list_xml list_json)]; } sub list { ... } sub list_xml { ... } sub list_json { ... }
$oView->create; Populates $oSelf->model with its expected parameters from the CGI block, then calls $oModel->create;
my $tt = $oView->tt;
e.g.
sub tt_opts { return { COMPILE_EXT => '.ttc', COMPILE_DIR => '/ramdisk', }; }
sub init { my $self = shift; $self->add_tt_filter('foo_filter', sub { my $string = shift; $string =~ s/foo/bar/smxg; return $string; }); return; }
my $hrFilters = $oView->tt_filters;
$oView->util($oUtil); my $oUtil = $oView->util;
$oView->model($oModel); my $oModel = $oView->model;
$oView->action($sAction); my $sAction = $oView->action;
$oView->aspect($sAction); my $sAction = $oView->aspect;
$oView->content_type($sContentType); my $sContentType = $oView->content_type;
$oView->charset($sCharSet); my $sCharSet = $oView->charset;
$oView->decor($bDecorToggle); my $bDecorToggle = $oView->decor;
my $bStreamedResponse = $oView->streamed;
Usually set by the controller, after processing the request. Used for remapping requests to classes (specifically things of the form application::(model|view)::something::somethingelse . $oView->entity_name($sEntityName); my $sEntityName = $oView->entity_name;
my $sActionOutput = $oView->actions;
$oView->redirect($sURL); $oView->redirect($sURL, $sStatus); # optional status
my $oHeaders = $oView->headers; $oView->headers->header('Status', 500); # usually symbolic named values from HTTP::Status
Process template.tt2 with standard parameters, output to stdout. $oView->process_template('template.tt2'); Process template.tt2 with standard parameters plus extras, output to stdout. $oView->process_template('template.tt2', {extra=>'params'}); Process template.tt2 with standard plus extra parameters and output into $to_scalar. $oView->process_template('template.tt2', {extra=>'params'}, $to_scalar);
$oView->output_buffer(q[my string]); $oView->output_buffer(@aStrings);
$oView->output_prepend(q[my string]); $oView->output_prepend(@aStrings);
$oView->output_end;
$oView->output_finished(1); $oViwe->output_finished(0);
$oView->output_flush;
$oView->output_reset;
If you're producing applications of moderate complexity, you almost certainly want to disable autoescaping and handle it more cleverly yourself. Subclass ClearPress::view and set self->autoescape to zero or override the subroutine: sub autoescape { return 0; }
$oView->decorator($oDecorator); my $oDecorator = $oView->decorator();
Set $ClearPress::view::DEBUG_L10N = 1 to report missing locali[zs]ation strings. Set $ClearPress::view::DEBUG_OUTPUT = 1 to report output buffer operations. Set $ClearPress::view::TRAP_REDIR_OVERFLOW = 1024 to enable experimental redirect header overflow handling after that many bytes
Roger Pettett, <rpettett@cpan.org>
Copyright (C) 2008 Roger Pettett
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install ClearPress, copy and paste the appropriate command in to your terminal.
cpanm
cpanm ClearPress
CPAN shell
perl -MCPAN -e shell install ClearPress
For more information on module installation, please visit the detailed CPAN module installation guide.