OpenInteract::UI::Main 1.62 review

Download
by rbytes.net on

OpenInteract::UI::Main is the primary user interface assembly 'conductor'. SYNOPSIS my $page = OpenInteract::UI::Mai

License: Perl Artistic License
File size: 642K
Developer: Chris Winters
0 stars award from rbytes.net

OpenInteract::UI::Main is the primary user interface assembly 'conductor'.

SYNOPSIS

my $page = OpenInteract::UI::Main->handler();
send_http_headers();
print $page;

# Subclass to define a new method for looking up template names:

package OpenInteract::UI::LanguageChoice;

use base qw( OpenInteract::UI::Main );

my $DEFAULT_LANGUAGE = 'en';

sub choose_template {
my ( $class ) = @_;
my ( $language );
if ( $R->{auth}{is_logged_in} ) {
$language = $R->{auth}{user}->language;
}
$language ||= $R->apache->param( 'lang' )
|| $R->{session}{lang}
|| $DEFAULT_LANGUAGE;
my $R = OpenInteract::Request->instance;
my $template = $R->{theme}->property_value( "template_$language" )
|| $R->{theme}->property_value( 'main_template' );
return $template;
}

This is the handler that puts the main content generated together with the template that surrounds the content on every page.

The action has already been parsed from the URL for us so we look up the class/method used to generate the content and call them. We then put that content into the main template which is specified in our theme, unless we have received another directive to use a separate template or no template at all.

Another alternative is that the content handler needs to return a file that is not HTML, such as a PDF, graphic, word processing document, archive, or whatever. If so the content handler should put the complete filename in the $R->{page}->{send_file} key.

A content author can set a main template to use for the generated content by setting:

$R->{page}{_template_name_}

to the name of the template to use. This should be a fully-qualified template name -- such as 'mypkg::mytemplate'. If you do not specify a package the OI template provider will try to find the template in the global template directory.

You can also set a template that might vary by theme. This is not the name of the template directly but rather a placeholder within the theme which holds the name of the template. For instance, say you created a 'spooky_template' and implemented it in multiple themes. Even though you as an author do not know what theme will be used, you can still pick the right template by setting:

$R->{page}{_template_key_}

And to use the 'simple' template, the author should set:

$R->{page}{_simple_}

to a true value. The default 'simple' template is 'base_simple', although you can set its name under the template_names key of your server configuration.

Finally, the author can also set:

$R->{page}{_no_template_}

to display the content without a template at all.

Main Template Variables

Any content handler can send information to be placed directly onto the main template by setting information using the $R->{main_template_vars} hashref. For instance:

$R->{main_template_vars}{current_weather} = 'Rainy and cold';

would set the 'current_weather' template variable for display on the main template and not on any of the content handlers.

Note that while this sounds useful (and it can be), you will probably use it only very rarely. The 'boxes' concept is more comprehensive and full-featured and will almost certainly do what you need.

Requirements:
Perl

OpenInteract::UI::Main 1.62 search tags