Home | Wiki | OI 1.x Docs | OI 2.x Docs OI logo

NAME

OpenInteract2::ContentGenerator::TemplateSource - Common routines for loading content from OI2 templates

SYNOPSIS

 # Sample from Text::Template content generator
 
 sub process {
     my ( $class, $template_config, $template_vars, $template_source ) = @_;
     my $SOURCE_CLASS = 'OpenInteract2::ContentGenerator::TemplateSource';
     my ( $source_type, $source ) = SOURCE_CLASS->identify( $template_source );
     if ( $source_type eq 'NAME' ) {
         my ( $template, $filename, $modified ) =
                         SOURCE_CLASS->load_source( $source );
         $source_type = 'STRING';
         $source      = $template;
     }
     $template_config->{TYPE}   = $source_type;
     $template_config->{SOURCE} = $source;
     my $template = Text::Template->new( %{ $template_config } );
     unless ( $template ) {
         oi_error "Failed to create template parsing object: ",
                  $Text::Template::ERROR;
     }
     my $content = $template->fill_in( HASH => $template_vars );
     unless ( $content ) {
         oi_error "Failed to fill in template: $Text::Template::ERROR";
     }

CLASS METHODS

identify( \%template_source )

Checks \%template_source for template information and returns a source type and source. Here are the types of information we check for in \%template_source and what's returned:

If none of these are found an exception is thrown.

Additionally, if we're able to pull a name from the template source and the current OpenInteract2::Controller object can handle it, we call add_template_used() on it, passing it the template name.

Returns: two item list of source type and source.

load_source( $template_name )

Fetches the template with the fully-qualified name $template_name and returns a three-item list with: contents, full filename, and the last modified time.

If the template is not found we throw an exception, and any exception thrown from the fetch propogates up.

Returns: a three-item list with: contents, full filename, and the last modified time (which is a DateTime object).

COPYRIGHT

Copyright (c) 2002-2003 Chris Winters. All rights reserved.

AUTHORS

Chris Winters <chris@cwinters.com>

Generated from the OpenInteract 1.99_03 source.


Home | Wiki | OI 1.x Docs | OI 2.x Docs
SourceForge Logo