From 222afc29e8aa8af0b4e8a4caf37debb0aee5be84 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Tue, 9 Dec 2003 02:00:10 +0000 Subject: [PATCH] * Move Class::Modular specific initialization to _init git-svn-id: file:///srv/don_svn/class_modular/trunk@8 96c6a18b-02ce-0310-9fca-9eb62c757ba6 --- Class/Modular/Modular.pm | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/Class/Modular/Modular.pm b/Class/Modular/Modular.pm index 978ef88..7977e7e 100644 --- a/Class/Modular/Modular.pm +++ b/Class/Modular/Modular.pm @@ -2,7 +2,7 @@ # under the terms of the GPL version 2, or any later version. See the # file README and COPYING for more information. Copyright 2003 by Don # Armstrong . -# $Id: Modular.pm,v 1.7 2003/11/05 04:55:14 don Exp $ +# $Id: Modular.pm,v 1.8 2003/12/09 02:00:10 don Exp $ package Class::Modular; @@ -53,7 +53,7 @@ use Carp; use Data::Copy qw(deep_copy); # Used for deep copying objects BEGIN{ - ($VERSION) = q$Revision: 1.7 $ =~ /\$Revision:\s+([^\s+])/; + ($VERSION) = q$Revision: 1.8 $ =~ /\$Revision:\s+([^\s+])/; $DEBUG = 0 unless defined $DEBUG; } @@ -82,12 +82,32 @@ sub new { my $self = {}; bless $self, $class; - $self->{_creation_args} = [@args]; + $self->_init(@args); return $self; } +=head2 _init + +=head3 Usage + + $self->_init(@args); + +=head3 Function + +Stores the arguments used at new so modules that are loaded later can +read them + +=cut + +sub _init { + my ($self,@creation_args) = @_; + + $self->{creation_args} = [@_]; +} + + =head2 load Title : load @@ -120,10 +140,11 @@ sub load($$;$) { if (not defined $self->{_subclasses}->{$subclass}){ eval { no strict 'refs'; + eval "require $subclass" or die $@; $self->_addmethods($subclass,&{"${subclass}::_methods"}($self,$options)); &{"${subclass}::_init"}($self); }; - warn $@ if $@; + die $@ if $@; $self->{_subclasses}->{$subclass} = {}; } else { @@ -155,7 +176,7 @@ sub _addmethods($@) { foreach my $method (@methods) { if (not $method =~ /^$subclass/) { - $method = $subclass.$method; + $method = $subclass.'::'.$method; } my ($method_name) = $method =~ /\:*([^\:]+)\s*$/; if (exists $self->{_methodhash}->{$method_name}) { @@ -384,12 +405,16 @@ sub AUTOLOAD{ return; } - if (defined $self->{_methodhash}->{$method}->{reference}) { + if (exists $self->{_methodhash}->{$method} and + defined $self->{_methodhash}->{$method}->{reference}) { eval { no strict 'refs'; - goto &$self->{_methodhash}->{$method}->{reference}; + goto &{$self->{_methodhash}{$method}{reference}}; } } + else { + croak "Undefined function $AUTOLOAD"; + } } -- 2.39.2