# 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.6 2003/10/25 03:01:35 don Exp $
+# $Id: Modular.pm,v 1.8 2003/12/09 02:00:10 don Exp $
package Class::Modular;
use Data::Copy qw(deep_copy); # Used for deep copying objects
BEGIN{
- ($VERSION) = q$Revision: 1.6 $ =~ /\$Revision:\s+([^\s+])/;
+ ($VERSION) = q$Revision: 1.8 $ =~ /\$Revision:\s+([^\s+])/;
$DEBUG = 0 unless defined $DEBUG;
}
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
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 {
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}) {
=head3 Function
Replaces UNIVERSAL's can method so that handled methods are reported
-correctly. Calls UNIVERSAL::can in the places where
+correctly. Calls UNIVERSAL::can in the places where we don't know
+anything it doesn't.
=head3 Returns
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";
+ }
}