The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Name

CatalystX::Usul::Controller - Application independent common controller methods

Version

This document describes CatalystX::Usul::Controller version 0.6.$Rev: 1166 $

Synopsis

   package CatalystX::Usul;
   use parent qw(CatalystX::Usul::Base CatalystX::Usul::Encoding);

   package CatalystX::Usul::Controller;
   use parent qw(Catalyst::Controller CatalystX::Usul);

   package YourApp::Controller::YourController;
   use parent qw(CatalystX::Usul::Controller);

Description

Provides methods common to all controllers. Implements the "big three" Catalyst API methods; begin, auto and end

Subroutines/Methods

Private methods begin with an _ (underscore). Private subroutines begin with __ (two underscores)

COMPONENT

The constructor stores a copy of the application instance for future reference. It does this to remain compatible with Catalyst::Controller whose constructor is no longer called

Extracts the phase number from the configuration's appldir attribute. The phase number is used to select one of a set of configuration files

Loads the controller plugins including;

CatalystX::Usul::Plugin::Controller::Cookies
CatalystX::Usul::Plugin::Controller::ModelHelper
CatalystX::Usul::Plugin::Controller::TokenValidation

auto

Control access to actions based on user roles and ACLs

This method will return true to allow the dispatcher to forward to the requested action, or this method will redirect to either the profile defined authentication action or one of the predefined default actions

These actions are permanently on public access; about, access_denied, captcha, action_closed, help, and view_source. Anonymous access is granted to actions that have the Public attribute set

Each action has a state attribute which is stored in the action's configuration file. Setting the actions state attribute to a value greater than 1 has the effect of closing the action to access. Instead the request is redirected to the action_closed action which is implemented by the root controller. The state attribute is set/unset by the access_control action in the Admin controller

The list of users/groups permitted to access an action (ACL) is stored in the configuration file. If an ACL has not been created only members of the support group will be allowed to access the action. ACLs can contain both user ids and group names. Group names are prefixed with an '@' character to distinguish them from user ids

The special ACL 'any' will allow any request to access the action. If the action does not permit public access requests from unknown users will be redirected to the authentication action which is defined in the package configuration

Requests for access to an action for which there is no authorisation will be redirected to the access_denied action which is implemented in the root controller

If no ACL for an action can be determined the the request is redirected to the error_page action

begin

This method stuffs the stash with most of data needed by TT to generate a 'blank' page. Begin methods in controllers forward to here. They can alter the stash contents before and after the call to this method

The file default.xml contains the meta data for each controller. Each controller has two configuration files which contain the controller specific data. One of the files is language independent and contains elements that define form fields and form keys. The language dependent file contains all the literal text strings used by that controller

The content type is either set from the configuration or if negotiate_content_type is true it is set to the first element of the array returned by "__accepted_content_types". The content type is used to lookup the current view in the content_map

Once the view has been selected it's deserialization method is called as required

The requested language is obtained by calling "__get_language"

Once the language is known the stash is further populated by calling "_stash_per_request_config"

deny_access

   $bool = $self->deny_access( $c );

Returns true if the user is denied access to the requested action

end

Calls add_token if the current page should contain a token and the plugin has been loaded. Traps and processes any errors. Forwards to the render method which has the action class attribute set to 'RenderView'

error_page

   $self->error_page( $c, $error_message_key, @args );

Generic error page which displays the specified message. The error message is localized by calling the localize method in the base class

redirect_to_page

   $self->redirect_to_page( $c, $page_name );

Takes a simple page name works out it's private path and then calls "redirect_to_path"

redirect_to_path

   $self->redirect_to_path( $c, $action_path, @args );

Sets redirect on the response object and then detaches. Defaults to the default_action config attribute if the action path is null

user_agent_ok

   $bool = $self->user_agent_ok( $c );

Detects use of the misery browser. Sets the skin to $c->config->{misery_skin} if its defined. Otherwise redirects to $c->config->{misery_page} if that is defined. Otherwise serves up a W3C validated page for Exploiter to render as garbage

Private Methods

_stash_browser_state

   $self->_stash_browser_state( $c );

Recover information stored in the browser state cookie. Uses the CatalystX::Usul::Plugin::Controller::Cookies module if it's loaded

_stash_user_attributes

   $self->_stash_user_attributes( $c );

Using this system sessions do not expire for three months. Instead the user key is expired after a period of inactivity. This method recovers information about the user and stores it on the stash. Everywhere else the stashed information is used as required

_parse_HasActions_attr

Associates the HasActions method attribute with the action class defined in the action_class configuration attribute

Private Subroutines

__accepted_content_types

   $types = __accepted_content_types( $c->req );

Taken from jshirley's Catalyst::Action::REST

Returns an array reference of content types accepted by the client

The list of types is created by looking at the following sources:

Content-type header

If this exists and the request is a GET request, this will always be the first type in the list

Content-type parameter

If the request is a GET request and there is a "content-type" parameter in the query string, this will come before any types in the Accept header

Accept header

This will be parsed and the types found will be ordered by the relative quality specified for each type

If a type appears in more than one of these places, it is ordered based on where it is first found.

__deserialize

   $data = __deserialize( $c, $verb );

Calls deserialize on the current view if the request is one of; options, post, or put

__get_language

   $language = __get_language( $c );

In order of precedence uses; the first capture argument, the accept-language headers from the request, the configuration default and finally the hard coded default which is en (English)

__is_language

   $bool = __is_language( $candidate, \@languages );

Tests to see if the given language is supported by the current configuration

__preferred_content_type

   $content_type = __preferred_content_type( $c->config, $c->req );

Returns the first accepted content type if the negotiate_content_type config attribute is true. Defaults to the config attribute content_type

__setup_plugins

   __setup_plugins( $app );

Load and instantiate any installed controller plugins. Called from the constructor

Diagnostics

None

Configuration and Environment

None

Dependencies

Catalyst::Controller
CatalystX::Usul
CatalystX::Usul::ModelHelper
HTTP::DetectUserAgent
HTTP::Headers::Util

Incompatibilities

There are no known incompatibilities in this module

Bugs and Limitations

There are no known bugs in this module. Please report problems to the address below. Patches are welcome

Author

Peter Flanigan, <Support at RoxSoft.co.uk>

License and Copyright

Copyright (c) 2008 Pete Flanigan. All rights reserved

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic

This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE