OpenInteract2::Setup - Base/Factory class for setup actions in OpenInteract2
# NOTE: Most of this is done for you in OI2::Context, but... # Run all setup actions: OpenInteract2::Setup->run_all_actions( $ctx ); # Run all setup actions, skipping one and its dependencies: OpenInteract2::Setup->run_all_actions( $ctx, 'read packages' ); # Later, run 'read packages' and its dependencies OpenInteract2::Setup->run_setup_for( 'read packages' ); # Create the setup action 'create temporary library' and run it my $ctx = OpenInteract2::Context->instance; my $setup = OpenInteract2::Setup->new( 'create temporary library' ); $setup->run( $ctx ) # Find available setup actions my @actions = OpenInteract2::Setup->list_actions; print "Available setup actions: ", join( "\n", sort @actions );
This class has two functions. First, it acts as a coordinator for groups of setup actions to be run. Second, it acts as a factory for those setup actions.
Setup actions are individual tasks that get run when the server starts up. (They may also be run when executing management tasks, or whenever you create a OpenInteract2::Context object.) Each task is a subclass of this one and should be quite focused in its job.
All setup actions are discovered at runtime -- as long as your action subclasses this one and is on
@INC we'll find it. Once read in your setup action is responsible for registering itself with this class, typically done with this as the last executable line:
OpenInteract2::Setup->register_factory_type( get_name() => __PACKAGE__ );
Every setup action is responsible for providing the following information about itself:
You can find all available setup actions like this:
my @actions = OpenInteract2::Setup->list_actions; print "Available setup actions: ", join( "\n", sort @actions );
Since we're using Class::Factory you can instantiate a setup action with its name:
my $setup = OpenInteract2::Setup->new( 'read packages' );
run_all_actions( $ctx, [ @action_names_to_skip ] )
run_setup_for( $action_name )
remove_skip_actions( @action_names_to_skip )
To the outside world each setup action has a very simple lifecycle:
my $setup = OpenInteract2::Setup->new( 'read packages' ); $setup->run();
When implementing a setup action you have a little more granularity.
execute( $ctx )
setup( $ctx )
execute( $ctx )
tear_down( $ctx )
See also OpenInteract2::ParamContainer for parameter manipulation methods.
new( $type, %params )
run( $ctx )
_read_ini( $ini_file )
Reads in the configuration file and returns the resulting OpenInteract2::Config::IniFile object. If we encounter an error we log the error and return undef.
Copyright (c) 2001-2005 Chris Winters. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Chris Winters <email@example.com>