# 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.2 2003/09/08 12:05:49 don Exp $
+# $Id: Modular.pm,v 1.3 2003/09/13 05:46:53 don Exp $
package Class::Modular;
use Data::Copy qw(deep_copy); # Used for deep copying objects
BEGIN{
- ($VERSION) = q$Revision: 1.2 $ =~ /\$Revision:\s+([^\s+])/;
+ ($VERSION) = q$Revision: 1.3 $ =~ /\$Revision:\s+([^\s+])/;
$DEBUG = 0 unless defined $DEBUG;
}
}
+=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
+
+sub DESTROY{
+ my $self = shift;
+ foreach my $subclass (keys %{$self->{_subclasses}}) {
+ # 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,$clone);
+ };
+ 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;
+ }
+ }
+}
+
=head2 AUTOLOAD