Home | Wiki | OI 1.x Docs | OI 2.x Docs |
OpenInteract2::Config::Initializer - Observable configuration initialization events
# Add an initializer in your package.conf name mypackage version 1.10 ... config_watcher OpenInteract::MyInitializerSpops config_watcher OpenInteract::MyInitializerAction # And the code in our package -- we'll dynamically add a rule from # 'My::Googlable' to a class where 'is_googlable' is set to 'yes' package OpenInteract::MyInitializerSpops; use strict; sub update { my ( $class, $type, $config ) = @_; return unless ( $type eq 'spops' );
if ( $config->{is_googlable} eq 'yes' ) { push @{ $config->{rules_from} }, 'My::Googable'; } } # Here's we'll dynamically add a filter to an action where # 'is_googlable' is 'yes' package OpenInteract::MyInitializerAction; use strict; use OpenInteract2::Context qw( CTX ); sub update { my ( $class, $type, $config ) = @_; return unless ( $type eq 'action' );
if ( $config->{is_googlable} eq 'yes' ) { OpenInteract2::Filter->add_filter_to_action( 'google', $config->{class} ); } }
This class provides a hook for observers to react to individual configuration events at server startup. The pseudocode for processing action and SPOPS configurations looks like this:
foreach package foreach config from package set core data do basic sanity checking trigger event
The event code can do whatever you like. This can be additional (but boring) checks on the data, such as ensuring that certain parameters are always arrayrefs, or always sorted in the same manner. This allows your implementation code to assume that everything will always be setup properly
More interesting you can provide concise hooks in your configuration that get expanded at runtime to something more complex.
For example, if you've read OpenInteract2::Manual::SPOPS you know that OpenInteract 2.x allows you to declare security for an SPOPS object with:
is_secure = yes
In 1.x you had to add a class to the ISA.
Or to enable fulltext searching of your object you can just add to your SPOPS configuration:
is_searchable = yes
and list the fields you'd like indexed. These are both implemented using this same event-based scheme.
What happens in the first case is that for every object that's tagged with 'is_secure' we simply add SPOPS::Secure to the object's 'isa' field. And in the second case we add OpenInteract2::FullText to the 'isa'.
Everything (or nearly everything) you can do in the event can be done in the configuration, so why bother? The primary reason is that it makes for much more concise configuration files. More concise configuration means you're less likely to mess it up and that you'll hopefully be more willing to modify it when necessary rather than throwing up your hands and hacking an ugly solution.
This is also done for the same reason that you create accessors instead of allowing direct access to your object's data structures. For instance, we may modify the full text indexing implementation to require only an SPOPS ruleset rather than full inheritance.
With the simple declaration we don't have to change any of our SPOPS configurations with the change. If we added the class directly to the 'isa' people would have to change the configuration manually, or we'd have to add a runtime hook to modify the 'isa' anyway.
This class also contains the default SPOPS and action configuration observers.
These are the initialization handlers for SPOPS events.
Configurations with 'is_secure' set to 'yes' get SPOPS::Secure added to the 'isa' key.
Configurations with the 'creation_security' key set to hashref have
the 'group' key rewritten to accommodate the modifications from
CREATION SECURITY_CONVERSION
in
OpenInteract2::Manual::SPOPS.
Configurations with one or more 'convert_date_field' entries get SPOPS::Tool::DateConvert added to the 'rules_from' key. Also issues a warning if 'convert_date_format' not defined
Configurations with 'is_searchable' set get OpenInteract2::FullText added to 'isa' as long as at least one field is listed in 'fulltext_field'.
Configurations defining 'display' with 'ACTION' and 'TASK' keys get a 'url' key with the properly rewritten URL; those with both 'ACTION' and 'TASK_EDIT' keys get a 'url_edit' key as well.
Configurations with 'field_discover' set to 'yes' get SPOPS::Tool::DBI::DiscoverField added to the 'rules_from' key.
Configurations using a DBI datasource get SPOPS::DBI and the database-specific class (e.g., SPOPS::DBI::Sybase) added to 'isa'.
Configurations using a LDAP datasource get SPOPS::LDAP added to 'isa'.
These are the handlers for action configuration events:
Read the hashref data from the 'action_info.default' server configuration key and assign it to the configuration where the configuration doesn't already have data defined.
In the action configuration you can use verbose descriptions of security levels like 'READ' and 'WRITE'. These get translated to the codes exported by SPOPS::Secure.
If the 'cache_param' key is defined ensure that the internal representation is an arrayref and the parameter names are always in the same order.
This just ensures parameters that can have zero or more values are set to empty arrayrefs (if none defined) or an arrayref with only one value (if one defined). The parameters are: 'url_alt'
You should never be using this class directly. But just in case...
new()
Creates a new object. (Doesn't hold anything right now.)
read_observers()
Class method to read the configuration observers from the server configuration and ask each package for its observers. These are collected and added to the observer list for this class.
Copyright (c) 2003 Chris Winters. All rights reserved.
Chris Winters <chris@cwinters.com>
Generated from the OpenInteract 1.99_03 source.