3
#---------------------------------------------------------------------------
5
# PURPOSE : A basic driver script for testing destruction of Bio::Root::Object.pm
6
# references and parent-child relationships.
7
# AUTHOR : Steve Chervitz (sac@bioperl.org)
9
# REVISION: $Id: destroy.pl,v 1.3 2002/01/11 08:05:40 sac Exp $
11
# Edit the use lib "...." line to point the directory
12
# containing your Bioperl modules.
13
#---------------------------------------------------------------------------
15
use lib "/home/steve/perl/bioperl";
16
use Bio::Root::Object ();
17
use Bio::Root::Global qw(:std);
21
print "\nParent-child driver.";
22
print "\n---------------------\n";
24
select(STDOUT); $| = 1;
26
my (@objs, $foo, $bar);
28
########################################
34
print "Verify memory usage and hit <RETURN> to continue.";<STDIN>;
37
print "Verify memory usage and hit <RETURN> to continue.";<STDIN>;
40
print "Verify memory usage and hit <RETURN> to continue.";<STDIN>;
43
print "Verify memory usage and hit <RETURN> to continue.";<STDIN>;
55
print "\n-------------------------------------------------------------\n";
56
print "Create Objects\n";
57
print "-------------------------------------------------------------\n\n";
60
push @objs, new Foo(-NAME =>"foo$_",
64
-FLAVOR =>'lemon-lime',
68
print "\nCreated $num Foo objects.\n";
75
# Test the _drop_child() method (considered a 'protected' method; end-users
76
# don't need to call this method in the normal course of affairs).
77
# Also shows the use of the global debug() function;
79
print "\n-------------------------------------------------------------\n";
80
print "Parent-Child Tester\n";
81
print "-------------------------------------------------------------\n\n";
85
my $foo = new Foo(-NAME =>"BigFoo",
89
-FLAVOR =>'lemon-lime',
92
print "\nAttempting to get the Foo object to drop its Bar child...\n";
95
$bar->parent->_drop_child($bar);
96
printf "%s is still alive and knows its parent (%s), but it is orphaned.\n", $bar->to_string, $bar->parent->to_string;
99
print "\nHere's proof: attempt to drop the Bar child again...\n";
100
eval { $bar->parent->_drop_child($bar); };
105
printf "\nAdding %s back to %s as an array data member\n", $bar->to_string, $bar->parent->to_string;
106
$bar->parent->{'array_member'}->[0] = $bar;
107
$bar->parent->_drop_child($bar);
109
printf "\nAdding %s back to %s as a hash data member\n", $bar->to_string, $bar->parent->to_string;
110
$bar->parent->{'hash_member'}->{'bar'} = $bar;
111
$bar->parent->_drop_child($bar);
115
print "\nTry to drop the Bar child again...\n";
116
eval { $bar->parent->_drop_child($bar); };
119
# Add Bar back to Foo for further processing.
120
$foo->{'Bar'} = $bar;
127
print "\n-------------------------------------------------------------\n";
129
print "-------------------------------------------------------------\n\n";
133
# print "\nDESTROYING BAR....\n";
138
while($_ = shift @objs) {
140
# $_->display; # uncomment this to check for creation/destruction of IOManagers
141
# printf "\nDESTROYING OBJ #%s: $_....\n", scalar @objs;
142
$_->destroy if ref $_;
153
print "\n-------------------------------------------------------------\n";
155
print "-------------------------------------------------------------\n\n";
157
print "Is foo alive?\n";
158
print "Foo: $foo\nBar: $bar\n";
160
print "\nAssigning onto foo.\n";