From: Chris W. <la...@us...> - 2005-01-24 17:17:43
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19387 Modified Files: Setup.pm ContentGenerator.pm Log Message: OIN-115: Move most functionality out of OI2::Setup and into individual classes that are discovered at runtime; remove all knowledge of setup procedures from OI2::Context into dependency tree created at runtime Index: Setup.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Setup.pm,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** Setup.pm 5 Dec 2004 20:54:03 -0000 1.54 --- Setup.pm 24 Jan 2005 17:17:32 -0000 1.55 *************** *** 4,677 **** use strict; ! use File::Copy qw( cp ); ! use File::Basename qw(); ! use File::Path qw(); ! use File::Spec::Functions qw( :ALL ); use Log::Log4perl qw( get_logger ); ! use OpenInteract2::Config::Initializer; ! use OpenInteract2::Config::GlobalOverride; ! use OpenInteract2::ContentGenerator; [...1334 lines suppressed...] ! B<new( $type, %params )> ! B<param( [ $key, [ $value ] ] )> ! B<run( $ctx )> ! B<_read_ini( $ini_file )> ! Reads in the configuration file and returns the resulting ! L<OpenInteract2::Config::IniFile> object. If we encounter an error we ! log the error and return undef. =head1 SEE ALSO ! L<Class::Factory> ! L<OpenInteract2::Context> =head1 COPYRIGHT Index: ContentGenerator.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/ContentGenerator.pm,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ContentGenerator.pm 18 Feb 2004 05:25:26 -0000 1.13 --- ContentGenerator.pm 24 Jan 2005 17:17:32 -0000 1.14 *************** *** 19,66 **** # FACTORY ! sub initialize_all_generators { ! my ( $class ) = @_; ! my $log_init = get_logger( LOG_INIT ); ! ! $log_init->is_debug && ! $log_init->debug( "Initializing all content generators" ); ! my $all_generator_info = CTX->lookup_content_generator_config; ! ! BIG_GENERATOR: ! while ( my ( $name, $generator_data ) = each %{ $all_generator_info } ) { ! next if ( $name eq 'default' ); ! my $generator_class = $generator_data->{class}; ! unless ( $generator_class ) { ! $log_init->error( "Cannot use generator '$name': no class ", ! "specified in key 'class'" ); ! next BIG_GENERATOR; ! } ! my $full_name = "[Name: $name] [Class: $generator_class]"; ! $log_init->is_debug && ! $log_init->debug( "Trying to require and initialize $full_name" ); ! eval "require $generator_class"; ! if ( $@ ) { ! $log_init->error( "Failed to require generator $full_name: $@" ); ! next BIG_GENERATOR; ! } ! my ( $generator ); ! eval { ! $generator = $generator_class->new( $name, $generator_class ); ! $generator->initialize( $generator_data ); ! }; ! if ( $@ ) { ! $log_init->error( "Require ok, but cannot initialize generator ", ! "$full_name. Error: $@" ); ! } ! else { ! $log_init->is_debug && ! $log_init->debug( "Successfully required and initialized ", ! "generator $full_name" ); ! $GENERATOR{ $name } = $generator; ! } ! } } - sub instance { my ( $class, $name ) = @_; --- 19,27 ---- # FACTORY ! sub add_generator { ! my ( $class, $name, $generator ) = @_; ! $GENERATOR{ $name } = $generator; } sub instance { my ( $class, $name ) = @_; *************** *** 81,86 **** my ( $pkg, $name, $gen_class ) = @_; my ( $package, @etc ) = caller; ! unless ( __PACKAGE__ eq $package ) { ! oi_error "Cannot call 'new()' from anywhere except " . __PACKAGE__; } return bless( { name => $name, --- 42,49 ---- my ( $pkg, $name, $gen_class ) = @_; my ( $package, @etc ) = caller; ! unless ( $package eq __PACKAGE__ || ! $package eq 'OpenInteract2::Setup::InitializeContentGenerators' ) { ! oi_error "Cannot call 'new()' from anywhere except " . __PACKAGE__ . " " . ! "or the relevant ::Setup action."; } return bless( { name => $name, *************** *** 144,166 **** =head2 Class Methods - B<initialize_all_generators()> - - Normally only called from - L<OpenInteract2::Setup|OpenInteract2::Setup>. This cycles through the - data in the configuration key C<content_generator>, performs a - C<require> on each class specified there, instantiates an object of - that class and calls C<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 - C<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. - B<instance( $generator_name )> --- 107,110 ---- *************** *** 180,183 **** --- 124,133 ---- required. + This may seem like it should be a class method but since each + generator is a singleton it's an object method. As a result 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. + The C<\%configuration_params> are pulled from the respective 'content_generator' section of the server configuration. So if you |