in reply to Re: Re: Re: Re: Inheritance and objects tied to a database
in thread Inheritance and objects tied to a database

Since $self->{data} is just an attribute, you can set it to undef after the untie in the child method, and adding an if (defined $self->{data}) {...} around the untie in the parent's DESTROY.

Hope this helps, -gjb-

Replies are listed 'Best First'.
Re: Re^5: Inheritance and objects tied to a database
by relax99 (Monk) on Dec 20, 2002 at 14:02 UTC
    Thank you! This seems to work. Below is my test code.
    use strict; use warnings; use Data::Dumper; my $control = Control->new(); my $app = Control::Main->new( %{$control} ); package Control; use Data::Dumper; sub new { my $class = shift; my $self = bless {}, ref($class) || $class; #my $dbh = Area::DB::connect(\$_connected) if !$_connected; #tie %{$self->{data}}, "Tie::ODBCSession", $dbh, $session_id; $self->{data} = {}; return $self; } sub DESTROY { my $self = shift; print "Destroying parent:\n"; print Dumper ($self) . "\n"; } package Control::Main; @Control::Main::ISA = qw(Control); use Data::Dumper; sub new { my $class = shift; my %args = @_; my $self = {}; bless $self, $class; # initialize with named parameters passed %{$self} = map { $_ => $args{$_} } keys(%args); # store action in the object $self->{data}->{action} = "test"; return $self; } sub DESTROY { my $self = shift; $self->{data} = undef; print "Destroying child:\n"; print Dumper ($self) . "\n"; }