From: Chris W. <la...@us...> - 2005-01-24 17:17:26
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19350 Modified Files: Context.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: Context.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Context.pm,v retrieving revision 1.78 retrieving revision 1.79 diff -C2 -d -r1.78 -r1.79 *** Context.pm 5 Dec 2004 21:10:32 -0000 1.78 --- Context.pm 24 Jan 2005 17:17:15 -0000 1.79 *************** *** 7,11 **** use Data::Dumper qw( Dumper ); use DateTime; - use DateTime::TimeZone; use Log::Log4perl qw( get_logger ); use OpenInteract2::Constants qw( :log ); --- 7,10 ---- *************** *** 18,22 **** my ( $log_spops, $log_act, $log_init ); ! sub version { return '1.99_05' } # Exportable deployment URL call -- main, images, static --- 17,21 ---- my ( $log_spops, $log_act, $log_init ); ! sub version { return '1.99_06' } # Exportable deployment URL call -- main, images, static *************** *** 49,54 **** require OpenInteract2::Controller; require OpenInteract2::Exception; ! my @CORE_FIELDS = qw( base_config server_config repository packages cache datasource_manager timezone timezone_object setup_class ); my @REQUEST_FIELDS = qw( request response controller user group is_logged_in is_admin ); --- 48,54 ---- require OpenInteract2::Controller; require OpenInteract2::Exception; + require OpenInteract2::Setup; ! my @CORE_FIELDS = qw( base_config repository packages cache datasource_manager timezone timezone_object setup_class ); my @REQUEST_FIELDS = qw( request response controller user group is_logged_in is_admin ); *************** *** 99,103 **** } ! $log_init = get_logger( LOG_INIT ); if ( $base_config ) { --- 99,103 ---- } ! $log_init ||= get_logger( LOG_INIT ); if ( $base_config ) { *************** *** 136,145 **** $params ||= {}; ! my %skip = (); if ( $params->{skip} ) { ! if ( ref $params->{skip} ne 'ARRAY' ) { ! $params->{skip} = [ $params->{skip} ]; } - %skip = map { $_ => 1 } @{ $params->{skip} }; } --- 136,147 ---- $params ||= {}; ! my @skip = (); if ( $params->{skip} ) { ! if ( ref $params->{skip} eq 'ARRAY' ) { ! push @skip, @{ $params->{skip} }; ! } ! else { ! push @skip, $params->{skip}; } } *************** *** 153,349 **** } ! my $server_config = $self->_read_server_config; ! $log_init->is_info && $log_init->info( "Assigned server config ok" ); ! ! my $setup_class = $self->lookup_class( 'setup' ); ! $self->setup_class( $setup_class ); ! $log_init->is_info && ! $log_init->info( "Will use setup class '$setup_class'" ); ! eval "require $setup_class"; ! if ( $@ ) { ! OpenInteract2::Exception->throw( ! "Cannot require setup class '$setup_class': $@" ); ! } ! $log_init->is_info && ! $log_init->info( "Required '$setup_class' ok; commencing setup" ); ! ! # go ahead and set the global context now... the other processes ! # mostly just need access to the global configuration ! ! $CTX = $self; ! ! my $setup = $setup_class->new(); ! $setup->run_pre_process(); ! ! my $timezone = $server_config->{timezone}; ! unless ( $timezone ) { ! $timezone = 'America/New_York'; ! $log_init->warn( ! "No timezone set in server configuration! Please set the ", ! "configuration key 'Global.timezone' to a valid ", ! "DateTime::TimeZone value. (I'm going to be a cultural ", ! "imperialist and assume '$timezone')." ! ); ! } ! my $timezone_object = DateTime::TimeZone->new( name => $timezone ); ! $self->timezone( $timezone ); ! $self->timezone_object( $timezone_object ); ! ! $log_init->is_info && $log_init->info( "Assigned timezone ok" ); ! ! # Assign constants from server config to the context. ! ! $self->assign_deploy_url; ! $self->assign_deploy_image_url; ! $self->assign_deploy_static_url; ! $log_init->is_info && ! $log_init->info( "Assigned constants from server config ok" ); ! ! if ( $skip{ 'initialize repository' } ) { ! $skip{ 'initialize temp lib' }++; ! $skip{ 'initialize action' }++; ! $skip{ 'initialize spops' }++; ! $skip{ 'initialize controller' }++; ! $skip{ 'initialize indexer' }++; ! } ! else { ! my $repository = $setup->read_repository; ! if ( $repository ) { ! $self->repository( $repository ); ! my $packages = $setup->read_packages; ! $self->packages( $packages ); ! } ! $log_init->is_info && ! $log_init->info( "Opened repository and read package definitions ok" ); ! $setup->create_temp_lib( $params, $skip{ 'initialize temp lib' } ); ! } ! ! unless ( $skip{ 'initialize datasource' } ) { ! my $ds_manager_class = $server_config->{datasource_config}{manager}; ! eval "require $ds_manager_class"; ! $self->datasource_manager( $ds_manager_class ); ! $log_init->is_info && $log_init->info( "Assigned datasource manager ok" ); ! $setup->check_datasources(); ! } ! ! if ( $skip{ 'initialize action' } ) { ! $skip{ 'initialze controller' }++; ! } ! else { ! my $action_table = $setup->read_action_table; ! $log_init->is_info && $log_init->info( "Read action table ok" ); ! my $action_classes = $setup->require_action_classes( $action_table ); ! $setup->initialize_action_classes( $action_classes ); ! $setup->register_action_types; ! $log_init->is_info && $log_init->info( "Required action classes ok" ); ! $self->action_table( $action_table ); ! $log_init->is_info && $log_init->info( "Assigned action table ok" ); ! } ! ! unless ( $skip{ 'initialize spops' } ) { ! my $spops_config = $setup->read_spops_config; ! $log_init->is_info && $log_init->info( "Read SPOPS configurations ok" ); ! unless ( $skip{ 'activate spops' } ) { ! $setup->activate_spops_classes( $spops_config ); ! $log_init->is_info && $log_init->info( "Activated SPOPS classes ok" ); ! } ! $self->spops_config( $spops_config ); ! $log_init->is_info && $log_init->info( "Assigned SPOPS table ok" ); ! } ! ! unless ( $skip{ 'initialize observer' } ) { ! $setup->initialize_observers; ! $log_init->is_info && ! $log_init->info( "Initialized observers ok" ); ! } ! ! unless ( $skip{ 'initialize messages' } ) { ! $setup->read_localized_messages; ! $log_init->is_info && $log_init->info( "Read localized messages ok" ); ! } ! ! unless ( $skip{ 'initialize indexer' } ) { ! $setup->initialize_indexers; ! } ! ! # Not optional... ! ! my $system_classes = $setup->read_system_classes; ! $log_init->is_info && ! $log_init->info( "Required system classes ok: ", ! join( ', ', @{ $system_classes } ) ); ! ! # Also not optional... ! ! $setup->register_in_factory( ! $server_config->{request}, 'OpenInteract2::Request' ); ! $setup->register_in_factory( ! $server_config->{response}, 'OpenInteract2::Response' ); ! ! unless ( $skip{ 'initialize session' } ) { ! $setup->require_session_classes( $server_config->{session_info} ); ! } ! ! unless ( $skip{ 'initialize cache' } ) { ! my $cache = $setup->create_cache; ! if ( $cache ) { ! $self->cache( $cache ); ! $log_init->is_info && $log_init->info( "Created cache ok" ); ! } ! else { ! $log_init->is_info && ! $log_init->info( "Cache not configured for use, ok" ); ! } ! } ! ! unless ( $skip{ 'initialize generator' } ) { ! $setup->initialize_content_generator; ! $log_init->is_info && $log_init->info( "Initialized content generators ok" ); ! } ! ! unless ( $skip{ 'initialze controller' } ) { ! $setup->initialize_controller; ! $log_init->is_info && ! $log_init->info( "Initialized controller and default actions ok" ); ! } ! $setup->run_post_process(); ! $log_init->is_debug && $log_init->info( "Initialized context ok" ); return $self; } - ######################################## - # SERVER CONFIG - - # Just grab the config and set the runtime info. ! sub _read_server_config { my ( $self ) = @_; ! my $base_config = $self->base_config; ! unless ( ref $base_config eq 'OpenInteract2::Config::Base' ) { ! OpenInteract2::Exception->new( ! "'base_config' property of context not set properly" ); ! } ! my $server_config_file = $base_config->get_server_config_file; ! unless ( $server_config_file ) { ! OpenInteract2::Exception->new( ! "Cannot read server configuration: file not defined ", ! "in base config" ); ! } ! my $config_type = $base_config->config_type; ! $log_init->is_info && ! $log_init->info( "Trying to read '$config_type' file '$server_config_file'" ); ! my $server_conf = OpenInteract2::Config->new( ! $config_type, { filename => $server_config_file } ); ! $log_init->is_info && $log_init->info( "Read server config ok" ); ! $server_conf->{dir}{website} = $base_config->website_dir; ! $server_conf->translate_dirs; ! $log_init->is_info && ! $log_init->info( "Translated server config directories ok" ); ! return $self->server_config( $server_conf ); } - ######################################## # CONFIGURATION ASSIGNMENTS --- 155,174 ---- } ! # This should call _initialize_singleton() when it's got the ! # context in a decent state ! OpenInteract2::Setup->run_all_actions( $self, \@skip ); ! $log_init->info( "Initialized context ok" ); return $self; } ! # Called from OI2::Setup after it's read the server configuration ! sub _initialize_singleton { my ( $self ) = @_; ! $CTX = $self; } ######################################## # CONFIGURATION ASSIGNMENTS *************** *** 354,357 **** --- 179,198 ---- # reflected in the configuration as well. + sub server_config { + my ( $self, $config ) = @_; + if ( $config ) { + $log_init ||= get_logger( LOG_INIT ); + $config->{dir}{website} = $self->base_config->website_dir; + $config->translate_dirs; + $log_init->info( "Translated server config directories ok" ); + + $self->{server_config} = $config; + $self->assign_deploy_url; + $self->assign_deploy_image_url; + $self->assign_deploy_static_url; + $log_init->info( "Assigned constants from server config ok" ); + } + return $self->{server_config}; + } # Where is this app deployed under? *************** *** 409,412 **** --- 250,257 ---- # What type of requests/responses are we getting/generating? + + # TODO: get rid of 'context_info' reference; these are strictly + # assigned by adapter now + sub assign_request_type { my ( $self, $type ) = @_; *************** *** 1147,1218 **** OpenInteract2::Context->create({ skip => 'activate spops' }); ! If you do not wish to read in the action table or SPOPS configuration: ! ! OpenInteract2::Context->create({ skip => [ 'initialize action', ! 'initialize spops' ] }); ! ! The steps we take to setup the site are listed below. Steps performed ! by L<OpenInteract2::Setup|OpenInteract2::Setup> are marked with the ! method called. ! ! =over 4 ! ! =item * ! ! Read in the server configuration and assign the debugging level from ! it. (Setup: C<read_server_config()>) (Skip: n/a) ! ! =item * ! ! Read in the package repository (Setup: C<read_repository()>) and all ! packages in the site (Setup: C<read_packages()>). (Skip: 'initialize ! repository') ! ! =item * ! ! Create a temporary library directory so all classes are found in one ! location. (Setup: C<create_temp_lib>) (Skip: 'initialize temp lib') ! ! =item * ! ! Require modules specified in the C<session_info> server configuration ! key under 'class' and 'impl_class'. (Skip: 'initialize session') ! ! =item * ! ! Read in the action table from the available packages. (Setup: ! C<read_action_table()>) We also ensure that all classes referenced in ! the action table are brought into the system via C<require>. (Skip: ! 'initialize action') ! ! =item * ! ! Read in the SPOPS object configurations from the available ! packages. (Setup: C<read_spops_config()>) Activate all SPOPS objects ! at once. (Setup: C<activate_spops_classes()>) (Skip: 'initialize ! spops'; you can also skip just the activation step with 'activate ! spops') ! ! =item * ! ! Read in the localized messages from all packages. (Setup: ! C<read_localized_messages()>). (Skip: 'initialize messages') ! ! =item * ! ! Create the cache. If it is not configured this is a no-op. (Setup: ! C<create_cache()>) (Skip: 'initialize cache') ! ! =item * ! ! Initialize all content generators. (Setup: ! C<initialize_content_generator()>) (Skip: 'initialize generator') ! =item * ! Initialize the main controller with default actions. (Skip: ! 'initialize controller'; also skipped with 'initialize action') ! =back Returns: the context object --- 992,1004 ---- OpenInteract2::Context->create({ skip => 'activate spops' }); ! If you do not wish to read in the action table or SPOPS configuration ! or perform any of the other actions that depend on them: ! OpenInteract2::Context->create({ skip => [ 'read action table', ! 'read spops config' ] }); ! You can get a list of all setup actions as a one-liner: ! perl -MOpenInteract2::Setup -e 'print join( ", ", OpenInteract2::Setup->list_actions )'; Returns: the context object *************** *** 1707,1719 **** The following are simple get/set properties of the context object. B<base_config>: Holds the L<OpenInteract2::Config::Base|OpenInteract2::Config::Base> object. This must be defined for the context to be initialized. - B<server_config>: Holds the - L<OpenInteract2::Config::IniFile|OpenInteract2::Config::IniFile> object - with the server configuration. This will be defined after the context - is initialized via C<setup()>. - B<repository>: Holds the L<OpenInteract2::Repository|OpenInteract2::Repository> object with --- 1493,1507 ---- The following are simple get/set properties of the context object. + B<server_config>: Holds the + L<OpenInteract2::Config::IniFile|OpenInteract2::Config::IniFile> + object with the server configuration. This will be defined during + context setup. When it is assigned we translate entries under 'dir' to + be properly located. We also call the various 'assign_deploy_*' + methods. + B<base_config>: Holds the L<OpenInteract2::Config::Base|OpenInteract2::Config::Base> object. This must be defined for the context to be initialized. B<repository>: Holds the L<OpenInteract2::Repository|OpenInteract2::Repository> object with |