Roger Pettett


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()

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;

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;

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

init - post-constructor initialisation hook for subclasses

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_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();








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.