SPUG: oddity (bug?) with isa()

Joel Grow largest at largest.org
Tue Mar 20 01:15:52 CST 2001


Hello SPUG-o-nauts,

Riley and I have been puzzling over some seemingly odd isa() behavior.  
Our understanding was that when you call

 Widget->isa('Thingie')

Perl would look in @Widget::ISA for 'Thingie'--if it's there isa() returns
true, else it returns false.  It appears, however, that something else is
also going on.  One thought is that Perl is also checking to see if
there's a 'Thingie' symbol table.

Consider the following code, a calling script and 2 versions of Widget.pm.
The only difference in the versions of the module is the 'package Thingy;'
line in the 2nd version.

use'ing version 1, the calling script outputs "Nope, not a Thingy\n".  
use'ing version 2, the calling script outputs "As I suspected, it's a
Thingy\n".  

why?

Joel

----8<----
#!/usr/local/bin/perl

# the calling script

use strict;
use Widget;

my $widgy = Widget->new();

print $widgy->isa('Thingy') ? "As I suspected, it's a Thingy\n" :
                              "Nope, not a Thingy\n";

----8<----

# Widget.pm, VERSION 1
package Widget;

use strict;
use vars '@ISA';

@ISA = 'Thingy';

sub new { bless {}, $_[0] }

1;

----8<----

# Widget.pm, VERSION 2
package Thingy;
package Widget;

use strict;
use vars '@ISA';

@ISA = 'Thingy';

sub new { bless {}, $_[0] }

1;



 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list