From: Teemu A. <in...@us...> - 2006-01-17 20:24:15
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27603/lib/OpenInteract2 Modified Files: Observer.pm Package.pm Log Message: package.ini can now be used to map observers to actions using observer_map section. Chris, please review. Index: Observer.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Observer.pm,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Observer.pm 21 Sep 2005 04:08:53 -0000 1.5 --- Observer.pm 17 Jan 2006 20:24:05 -0000 1.6 *************** *** 117,138 **** my $observer_registry = $class->_register_initial_observers( ! $observer_ini->{observer}, CTX->packages ); $li->is_info && $li->info( "Registered internal observers ok" ); CTX->set_observer_registry( $observer_registry ); ! my $mappings = $observer_ini->{map}; ! if ( ref $mappings eq 'HASH' ) { ! while ( my ( $observer_name, $action_info ) = each %{ $mappings } ) { ! my @actions = ( ref $action_info ) ! ? @{ $action_info } : ( $action_info ); ! foreach my $action_name ( @actions ) { ! $li->is_info && ! $li->info( "Trying to add observer '$observer_name' to ", ! "action '$action_name'" ); ! $class->add_observer_to_action( $observer_name, $action_name ); ! } ! } ! } return; } --- 117,128 ---- my $observer_registry = $class->_register_initial_observers( ! $observer_ini->{observer}, CTX->packages, $li ); $li->is_info && $li->info( "Registered internal observers ok" ); CTX->set_observer_registry( $observer_registry ); ! $class->_register_initial_mappings( ! $observer_ini->{map}, CTX->packages, $li ); ! return; } *************** *** 145,150 **** sub _register_initial_observers { ! my ( $class, $ini_observers, $packages ) = @_; ! my $li = get_logger( LOG_INIT ); my %observer_map = (); --- 135,140 ---- sub _register_initial_observers { ! my ( $class, $ini_observers, $packages, $li ) = @_; ! $li ||= get_logger( LOG_INIT ); my %observer_map = (); *************** *** 192,195 **** --- 182,211 ---- } + sub _register_initial_mappings { + my ( $class, $ini_mappings, $packages, $li ) = @_; + $li ||= get_logger( LOG_INIT ); + + # Cycle through packages' mappings and then ini_mappings. + + my @all_mappings = (); + push @all_mappings, $_->config->observer_map for @$packages; + push @all_mappings, $ini_mappings; + + foreach my $pkg ( @all_mappings ) { + next unless ( ref $mappings eq 'HASH' ); + + while ( my ( $observer_name, $action_info ) = each %{ $mappings } ) { + my @actions = ( ref $action_info ) + ? @{ $action_info } : ( $action_info ); + foreach my $action_name ( @actions ) { + $li->is_info && + $li->info( "Trying to add observer '$observer_name' to ", + "action '$action_name'" ); + $class->add_observer_to_action( $observer_name, $action_name ); + } + } + } + } + sub _require_module { my ( $class, $to_require ) = @_; *************** *** 231,236 **** allcaps = news ! # You can also declare the observer in your package's package.conf ! # file; it's mapped the same no matter where it's declared # File: pkg/mypackage-2.00/package.ini --- 247,252 ---- allcaps = news ! # You can also declare a class observer in your package's package.ini ! # file; it's mapped the same no matter where it's declared. # File: pkg/mypackage-2.00/package.ini *************** *** 242,247 **** [package observer] allcaps = OpenInteract2::Filter::AllCaps ! ! ... # Create the filter -- see OpenInteract2::Filter::AllCaps shipped --- 258,266 ---- [package observer] allcaps = OpenInteract2::Filter::AllCaps ! ! # You can also map observers to actions in package.ini. ! ! [package observer_map] ! allcaps = news # Create the filter -- see OpenInteract2::Filter::AllCaps shipped *************** *** 422,426 **** =head2 Configuration: Mapping the Observer to an Action ! Mapping an observer to an action is exclusively done in C<$WEBSITE_DIR/conf/observer.ini>. Under the 'map' section you assign an observer to one or more actions. Here as assign the observer 'wiki' --- 441,445 ---- =head2 Configuration: Mapping the Observer to an Action ! Mapping an observer to an action is done in C<$WEBSITE_DIR/conf/observer.ini>. Under the 'map' section you assign an observer to one or more actions. Here as assign the observer 'wiki' *************** *** 438,441 **** --- 457,467 ---- object_tag = news + Mappings can also be defined in package.ini in the 'observer_map' + section: + + [observer_map] + @,wiki = news,page + object_tag = news + Note that the mapping is ignorant of: Index: Package.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Package.pm,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** Package.pm 22 Oct 2005 21:56:03 -0000 1.62 --- Package.pm 17 Jan 2006 20:24:05 -0000 1.63 *************** *** 1,1448 **** ! package OpenInteract2::Package; # $Id$ use strict; ! use base qw( Exporter Class::Accessor::Fast ); ! use Archive::Zip qw( :ERROR_CODES ); ! use Cwd qw( cwd ); ! use Data::Dumper qw( Dumper ); ! use ExtUtils::Manifest (); [...2423 lines suppressed...] ! events at server startup. You can use this to create custom, concise ! directives for your SPOPS and/or Action configurations that get ! expanded into either more meaningful information or into data that can ! only be found at runtime. That may be a little abstract: see ! L<OpenInteract2::Config::Initializer|OpenInteract2::Config::Initializer> ! for examples. ! C<description> ($*) ! Description of this package. =head1 SEE ALSO ! L<OpenInteract2::Package|OpenInteract2::Package> ! L<Class::Accessor|Class::Accessor> ! L<OpenInteract2::Config::Ini> =head1 COPYRIGHT |