Phoenix.pm: OOP quandry the sequel (and the answer)

Bryan Lane Bryan.Lane at VITALPS.COM
Wed Feb 9 12:46:55 CST 2000


Good job.  I knew you would figure it out.  It makes sense about the
packages needing to come before the object is instantiated.  I'm not sure
why none of us saw it.

Later,
Bryan

-----Original Message-----
From: Douglas E. Miles [mailto:doug.miles at ns2.phoenix.bowne.com]
Sent: Wednesday, February 09, 2000 11:33 AM
To: Phoenix.pm
Subject: Phoenix.pm: OOP quandry the sequel (and the answer)


OK,

I discovered what my problem was.  It was simply that my packages needed
to come before the object is instantiated.  Here is a simple example:

# This works!

#!/usr/bin/perl

foreach $symname (sort(keys(%main::)))
{

  local *sym = $main::{$symname};
  print "\$$symname is defined\n" if defined $sym;
  print "\@$symname is defined\n" if defined @sym;
  print "\%$symname is defined\n" if defined %sym;
  print "\&$symname is defined\n" if defined &sym;

}

package XML_ObjTree::report;

@ISA = qw(XML_ObjTree);

package XML_ObjTree;

sub new
{

  print "NEW!!!!!!!!!!!!!\n";

}

my $obj = XML_ObjTree::report->new;


# This doesn't work.
#!/usr/bin/perl

foreach $symname (sort(keys(%main::)))
{

  local *sym = $main::{$symname};
  print "\$$symname is defined\n" if defined $sym;
  print "\@$symname is defined\n" if defined @sym;
  print "\%$symname is defined\n" if defined %sym;
  print "\&$symname is defined\n" if defined &sym;

}

my $obj = XML_ObjTree::report->new;

package XML_ObjTree::report;

@ISA = qw(XML_ObjTree);

package XML_ObjTree;

sub new
{

  print "NEW!!!!!!!!!!!!!\n";

}

Notice the difference in where this line is:

my $obj = XML_ObjTree::report->new;

I was under the mistaken assumption that this was all resolved at
compile time.  Apparently, this is not the case.

Bonus:

I also discovered something else I didn't know.  XML_ObjTree::report is
stored under the XML_ObjTree:: symbol table - not under main::.  This
suprised me because everything I have seen says that there is no implied
relationship.  I guess that just refers to the fact that there is no
automatic inheritance.  Hope this is helpful.  It was definitely
educational to me.

-- 
Socrates is a man. All men are mortal. Therefore, all mortals are
Socrates.



More information about the Phoenix-pm mailing list