* Fix _clone calling
* Move DESTROY documentation
* Fix destroy calling
git-svn-id: file:///srv/don_svn/class_modular/trunk@18
96c6a18b-02ce-0310-9fca-
9eb62c757ba6
eval {
no strict 'refs';
eval "require $subclass" or die $@;
eval {
no strict 'refs';
eval "require $subclass" or die $@;
- # Use subclass::METHODS if it exists [use constants METHODS => qw(foo)]
- $self->_addmethods($subclass,&{"${subclass}::_methods"}($self,$options));
- &{"${subclass}::_init"}($self);
+ my @methods = ();
+ if (UNIVERSAL::can($subclass,'METHODS')) {
+ push @methods,&{"${subclass}::METHODS"};
+ }
+ elsif (UNIVERSAL::can($subclass,'METHODS')) {
+ push @methods,&{"${subclass}::_methods"};
+ }
+ $self->_addmethods($subclass,@methods);
+ my $initref = UNIVERSAL::can($subclass,'_init');
+ &$initref($self,$options) if defined $initref;
};
die $@ if $@;
$self->{_subclasses}->{$subclass} = {};
};
die $@ if $@;
$self->{_subclasses}->{$subclass} = {};
# XXX Switch to can instead.
eval {
no strict 'refs';
# XXX Switch to can instead.
eval {
no strict 'refs';
- &$subclass::_clone($self,$clone);
+ &{"${subclass}::_clone"}($self,$clone);
};
if ($@) {
# Die unless we've hit an undefined subroutine.
};
if ($@) {
# Die unless we've hit an undefined subroutine.
- die $@ unless $@ =~ /Undefined\s*subroutine\s*\&.*\:\:\_clone/;
+ die $@ unless $@ =~ /Undefined\s*function\s*.*\:\:\_clone/;
warn "$subclass doesn't have a _clone method\n$@" if $DEBUG;
}
warn "$subclass doesn't have a _clone method\n$@" if $DEBUG;
}
sub _init {
my ($self,@creation_args) = @_;
sub _init {
my ($self,@creation_args) = @_;
- $self->{creation_args} = [@_];
+ $self->{creation_args} = [@creation_args];
-=head2 DESTROY
-
-=head3 Usage
-
-Called by perl.
-
-=head3 Function
-
-Calls all subclass _destroy methods.
-
-Subclasses need only implement a _destroy method if they have
-references that need to be uncircularized, or things that should be
-disconnected or closed.
-
-=cut
-
=head2 _addmethods
=head3 Usage
=head2 _addmethods
=head3 Usage
+=head2 DESTROY
+
+=head3 Usage
+
+Called by perl.
+
+=head3 Function
+
+Calls all subclass _destroy methods.
+
+Subclasses need only implement a _destroy method if they have
+references that need to be uncircularized, or things that should be
+disconnected or closed.
+
+=cut
+
# use eval to try and call the subclasses _destroy method.
# Ignore no such function errors, but trap other types of
# errors.
# use eval to try and call the subclasses _destroy method.
# Ignore no such function errors, but trap other types of
# errors.
- eval {
- no strict 'refs';
- &$subclass::_destroy($self);
- };
- if ($@) {
- # Die unless we've hit an undefined subroutine.
- die $@ unless $@ =~ /Undefined\s*subroutine\s*\&.*\:\:\_clone/;
- warn "$subclass doesn't have a _clone method\n$@" if $DEBUG;
- }
+ my $destroy_func = UNIVERSAL::can($subclass,'_destroy');
+ &$destroy_func($self) if defined $destroy_func;