NAME

OpenInteract2::ContentGenerator - Coordinator for classes generating content

SYNOPSIS

# In server startup

OpenInteract2::ContentGenerator->initialize_all_generators;

# Whenever you want a generator use either of these. (This is handled
# behind the scenes in OI2::Action->generate_content for most uses.)

my $generator = OpenInteract2::ContentGenerator->instance( 'TT' );
my $generator = CTX->content_generator( 'TT' );

# Every content generator implements 'generate()' which marries the
# parameters with the template source and returns content

$content = $generator->generate( \%template_params,
                                 \%content_params,
                                 \%template_source );

DESCRIPTION

This is a simple coordinating front end for the classes that actually generate the content -- template processors, SOAP response generators, etc. (You could probably put some sort of image generation in here too, but that would be mad.)

METHODS

Class Methods

initialize_all_generators()

Normally only called from OpenInteract2::Setup. This cycles through the data in the configuration key content_generator, performs a require on each class specified there, instantiates an object of that class and calls initialize() on it, passing in the data (hashref) from the respective 'content_generator' configuration section as the only argument.

This object is a singleton and will be returned whenever you call instance() (below). So you can save state that may be used by your generator many times throughout its lifecycle. Note that it is not cleared out per-request, so the data it stores should not be specific to a particular user or session.

Returns: nothing. If errors occur in the generator classes we log them.

instance( $generator_name )

Return an object representing the given content generator. If $generator_name is not found an exception is thrown.

Returns: an object with OpenInteract2::ContentGenerator as a parent.

Subclass Implementation Methods

initialize( \%configuration_params )

Object method that gets called only once. Since this is normally at server startup you can execute processes that are fairly intensive if required.

The \%configuration_params are pulled from the respective 'content_generator' section of the server configuration. So if you had:

[content_generator Foo]
class     = OpenInteract2::ContentGenerator::Foo
max_size  = 2000
cache_dir = /tmp/foo

You would get the following hashref passed into OpenInteract2::ContentGenerator::Foo->initialize:

{
  class     => 'OpenInteract2::ContentGenerator::Foo',
  max_size  => '2000',
  cache_dir => '/tmp/foo',
}

You may also store whatever data in the object hashref required. The parent class only uses 'name' and 'class', so as long as you keep away from them you have free rein.

generate( \%template_params, \%content_params, \%template_source )

Actually generates the content. This is the fun part!

COPYRIGHT

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

AUTHORS

Chris Winters <chris@cwinters.com>