The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

OpenInteract2::Setup - Base/Factory class for setup actions in OpenInteract2

SYNOPSIS

 # 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 );

DESCRIPTION

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:

  • Name - Every setup action has a name that must be returned by get_name().

  • Dependencies - Every setup action may depend on other actions so we can determine the order in which to run them. It may declare these by returning a list from get_dependencies().

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' );

COORDINATING METHODS

list_actions()

get_setup_dependencies()

run_all_actions( $ctx, [ @action_names_to_skip ] )

run_setup_for( $action_name )

remove_skip_actions( @action_names_to_skip )

SUBCLASSING

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.

Required methods

get_name()

execute( $ctx )

Optional methods

get_dependencies()

init()

setup( $ctx )

execute( $ctx )

tear_down( $ctx )

Common functionality

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.

SEE ALSO

Class::Factory

OpenInteract2::Context

COPYRIGHT

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.

AUTHORS

Chris Winters <chris@cwinters.com>