]> git.donarmstrong.com Git - class_modular.git/.git/blobdiff - Class/Modular/Modular.pm
* Move Class::Modular specific initialization to _init
[class_modular.git/.git] / Class / Modular / Modular.pm
index 978ef889ce4991a6598cd69d913069341b85808f..7977e7e2ca44ccc0a88a6f37913d933bd2a15cf3 100644 (file)
@@ -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 <don@donarmstrong.com>.
-# $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";
+     }
 }