NAME

ClearPress::view - MVC view superclass

VERSION

$Revision: 468 $

SYNOPSIS

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[];

DESCRIPTION

View superclass for the ClearPress framework

SUBROUTINES/METHODS

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;

$oView->template_name($sOverriddenName);

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

my $sMethodName = $oView->method_name;

add_warning

$oView->add_warning($sWarningMessage);

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

$oView->create;

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

e.g.

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;
  $self->add_tt_filter('foo_filter',
                       sub {
                            my $string = shift;
                            $string =~ s/foo/bar/smxg;
                            return $string;
                           });
  return;
}

tt_filters - hashref of configured template toolkit filters

my $hrFilters = $oView->tt_filters;

util - get/set accessor for utility object

$oView->util($oUtil);
my $oUtil = $oView->util;

model - get/set accessor for data model object

$oView->model($oModel);
my $oModel = $oView->model;

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

$oView->action($sAction);
my $sAction = $oView->action;

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

$oView->aspect($sAction);
my $sAction = $oView->aspect;

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

$oView->content_type($sContentType);
my $sContentType = $oView->content_type;

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

$oView->charset($sCharSet);
my $sCharSet = $oView->charset;

decor - get/set accessor for page decoration toggle

$oView->decor($bDecorToggle);
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 .

 $oView->entity_name($sEntityName);
 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.

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

output_buffer - For streamed output: queue a string for output

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

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

$oView->output_end;

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

$oView->output_finished(1);
$oViwe->output_finished(0);

output_flush - For streamed output: flush output buffer to STDOUT

$oView->output_flush;

output_reset - clear data pending output

$oView->output_reset;

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

$oView->decorator($oDecorator);
my $oDecorator = $oView->decorator();

DIAGNOSTICS

CONFIGURATION AND ENVIRONMENT

DEPENDENCIES

base
strict
warnings
Class::Accessor
Template
Template::Filters
HTML::Entities
XML::Simple
ClearPress::util
Carp
English
POSIX

INCOMPATIBILITIES

BUGS AND LIMITATIONS

AUTHOR

Roger Pettett, <rpettett@cpan.org>

LICENSE AND COPYRIGHT

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.