From: Chris W. <la...@us...> - 2005-01-24 16:58:48
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14235 Modified Files: Manage.pm Log Message: move code to find factory subclasses to OI2::Util Index: Manage.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Manage.pm,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** Manage.pm 9 Nov 2004 13:49:37 -0000 1.41 --- Manage.pm 24 Jan 2005 16:58:38 -0000 1.42 *************** *** 5,9 **** use strict; use base qw( Exporter Class::Factory Class::Observable ); - use Carp qw( carp ); use Cwd qw( cwd ); use File::Spec::Functions qw( :ALL ); --- 5,8 ---- *************** *** 78,82 **** my $error = $@; if ( $@ ) { - #carp "Caught error: $@"; $self->notify_observers( progress => 'Failed task' ); $self->param( 'task_failed', 'yes' ); --- 77,80 ---- *************** *** 95,100 **** # STANDARD PARAMETER DESCRIPTIONS AND DESCRIPTORS - # Provides some - sub get_param_description { my ( $self, $param_name ) = @_; --- 93,96 ---- *************** *** 568,636 **** ############################## ! # INITIALZE ALL TASKS ! ! # Now that all our stuff everything is loaded, find all management ! # tasks anywhere on @INC ! ! my %MANAGE_FILES = (); ! ! sub find_management_tasks { ! my ( $class, @dirs ) = @_; ! ! foreach my $lib_dir ( @dirs ) { ! next unless ( $lib_dir ); ! my $manage_dir = catdir( $lib_dir, 'OpenInteract2', 'Manage' ); ! next unless ( -d $manage_dir ); ! eval { _find_descend( $manage_dir ) }; ! if ( $@ ) { ! carp "Error trying to find management tasks: $@\n"; ! } ! } ! ! # Now grab the class names from the files stored in %MANAGE_FILES ! # so we don't try to include the same class from different files ! # -- this normally only happens for developers who have the OI2 ! # lib directory in their PERL5LIB and who are running tests ! ! my %MANAGE_CLASSES = (); ! foreach my $file ( sort keys %MANAGE_FILES ) { ! my $file_class = $file; ! $file_class =~ s/^.*OpenInteract2/OpenInteract2/; ! $file_class =~ s/\.pm$//; ! $file_class =~ s/\W/::/g; ! $MANAGE_CLASSES{ $file_class } ||= $file; ! } ! ! # Why 'sort'? It ensures that classes further up the hierarchy ! # (e.g., 'OI2::Manage::Website') get required before their ! # children; otherwise we get lots of 'subroutine foo redefined' ! # messages under '-w', irritating. ! ! foreach my $manage_class ( sort keys %MANAGE_CLASSES ) { ! #warn "Requiring file '$manage_class'\n"; ! eval "require $manage_class"; ! if ( $@ ) { ! carp "Failed to bring in library '$manage_class': $@"; ! } ! } ! } ! ! sub _find_descend { ! my ( $lib_dir ) = @_; ! opendir( MANAGEDIR, $lib_dir ) ! || die "Cannot open directory '$lib_dir': $!"; ! my @entries = grep ! /^\./, readdir( MANAGEDIR ); ! foreach my $entry ( @entries ) { ! my $full_entry_dir = File::Spec->catdir( $lib_dir, $entry ); ! if ( -d $full_entry_dir ) { ! _find_descend( $full_entry_dir ); # let this error bubble ! } ! next unless ( $entry =~ /\.pm$/ ); ! my $full_filename = File::Spec->catfile( $lib_dir, $entry ); ! $MANAGE_FILES{ $full_filename } = 1; ! } ! } ! __PACKAGE__->find_management_tasks( @INC ); --- 564,572 ---- ############################## ! # FIND ALL MANAGEMENT TASKS ! OpenInteract2::Util->find_factory_subclasses( ! 'OpenInteract2::Manage', @INC ! ); |