View on
Roger Pettett > ClearPress > ClearPress::view



Annotate this POD


Open  0
View/Report Bugs
Module Version: v476.4.2   Source  


ClearPress::view - MVC view superclass


$Revision: 470 $


  my $oView = ClearPress::view::<subclass>->new({util => $oUtil});

  print $oView->decor?
    q[Content-type: ].$oView->content_type."\n\n";

  print $oView->render;

  print $oView->decor?$oDecorator->footer:q[];


View superclass for the ClearPress framework


new - constructor

  my $oView = ClearPress::view::<subclass>->new({util => $oUtil, ...});

init - additional post-constructor hook

setup_filters - adds default tt_filters, called by ->new()

locales - hashref of locale lexicons to feed Locale::Maketext::Lexicon

 Defaults are:

   '*' => [Gettext => sprintf q[%s/po/*.po], $util->data_path],
   'en' => ['Auto'],

determine_aspect - URI processing

 sets the aspect based on the HTTP Accept: header

 - useful for API access setting Accept: text/xml

template_name - the name of the template to load, based on view class and method_name. Can be overridden

  my $sTemplateName = $oView->template_name;


method_name - the name of the method to invoke on the model, based on action and aspect

  my $sMethodName = $oView->method_name;



warnings - an arrayref of warning strings set for this view

  my $arWarningStrings = $oView->warnings;

authorised - Verify authorisation for this view

  This should usually take into account $self->action which suggests
  read or write access.

  my $bIsAuthorised = $oView->authorised;

render - generates and returns content for this view

  my $sViewOutput = $oView->render;

streamed_aspects - an arrayref of aspects which perform streamed output.

  Implemented in subclass:

  sub streamed_aspects {
    return [qw(list list_xml list_json)];

  sub list { ... }
  sub list_xml { ... }
  sub list_json { ... }

list - stub for entity list actions

create - A default model creation/save method


  Populates $oSelf->model with its expected parameters from the CGI
  block, then calls $oModel->create;

add - stub for single-entity-creation actions

edit - stub for single-entity editing

read - stub for single-entity-view actions

update - stub for entity update actions

delete - stub for entity delete actions

tt - a configured Template (TT2) object

  my $tt = $oView->tt;

tt_opts - a hashref of options for Template::Toolkit construction


 sub tt_opts {
   return {
           COMPILE_EXT => '.ttc',
           COMPILE_DIR => '/ramdisk',

add_tt_filter - add a named template toolkit content filter, usually performed in init

  sub init {
    my $self = shift;
                         sub {
                              my $string = shift;
                              $string =~ s/foo/bar/smxg;
                              return $string;

tt_filters - hashref of configured template toolkit filters

  my $hrFilters = $oView->tt_filters;

util - get/set accessor for utility object

  my $oUtil = $oView->util;

model - get/set accessor for data model object

  my $oModel = $oView->model;

action - get/set accessor for the action being performed on this view

  my $sAction = $oView->action;

aspect - get/set accessor for the aspect being performed on this view

  my $sAction = $oView->aspect;

content_type - get/set accessor for content mime-type (Content-Type HTTP header)

  my $sContentType = $oView->content_type;

charset - get/set accessor for content charset (Content-Type header charset) - default UTF-8

  my $sCharSet = $oView->charset;

decor - get/set accessor for page decoration toggle

  my $bDecorToggle = $oView->decor;

streamed - current aspect is streamed, based on @{streamed_aspects}

  my $bStreamedResponse = $oView->streamed;

entity_name - get/set accessor for the entity_name

 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 .

  my $sEntityName = $oView->entity_name;

actions - templated output for available actions

  my $sActionOutput = $oView->actions;

redirect - Apache internal redirect via mod-perl subrequest


  $oView->redirect($sURL, $sStatus); # optional status

list_xml - default passthrough to list for xml service

read_xml - default passthrough to read for xml service

create_xml - default passthrough to create for xml service

update_xml - default passthrough to update for xml service

delete_xml - default passthrough to delete for xml service

list_ajax - default passthrough to list for ajax service

read_ajax - default passthrough to read for ajax service

create_ajax - default passthrough to create for ajax service

update_ajax - default passthrough to update for ajax service

delete_ajax - default passthrough to delete for ajax service

list_json - default passthrough to list for json service

read_json - default passthrough to read for json service

create_json - default passthrough to create for json service

update_json - default passthrough to update for json service

delete_json - default passthrough to delete for json service

list_csv - default passthrough to list for csv service

read_csv - default passthrough to read for csv service

create_csv - default passthrough to create for csv service

update_csv - default passthrough to update for csv service

delete_csv - default passthrough to delete for csv service

init - post-constructor initialisation hook for subclasses

headers - an HTTP::Headers object for responses

  my $oHeaders = $oView->headers;

  $oView->headers->header('Status', 500); # usually symbolic named values from HTTP::Status

process_template - process a template with standard parameters

  Process template.tt2 with standard parameters, output to stdout.


  Process template.tt2 with standard parameters plus extras, output to

  $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);

output_buffer - For streamed output: queue a string for output

  $oView->output_buffer(q[my string]);

output_prepend - prepend something for output - usually headers

  $oView->output_prepend(q[my string]);

output_end - For streamed output: flag no more output and flush buffer


output_finished - For streamed output: flag there's no more output


output_flush - For streamed output: flush output buffer to STDOUT


output_reset - clear data pending output


autoescape - turn auto-escaping of input on/off, usually in a subclass

 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; }

decorator - get/set accessor for decorator object for cases where a view needs to reset & resend the decorated header. Set by the controller during $view->render()

 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 = 1 to enable experimental redirect header overflow handling






Roger Pettett, <>


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.

syntax highlighting: