tags:

views:

556

answers:

4

I want to make a singleton class which extends DBI. should I be doing something like this:

use base 'Class::Singleton';
our @ISA = ('DBI');

or this:

our @ISA = ('Class::Singleton', 'DBI');

or something else?

Not really sure what the difference between 'use base' and 'isa' is.

Thanks.

+4  A: 

I think you should use the parent pragma instead of base as has been suggested in perldoc base.

Alan Haggai Alavi
Is 'parent' new in 5.10? It must be, as it's not in my 5.8 documentation.
Ether
I am not sure. However, quoting Chas's statement: "... The parent pragma is new as of Perl 5.10.1, but it is installable from CPAN if you have an older version of Perl. ..."
Alan Haggai Alavi
+5  A: 

http://stackoverflow.com/questions/876471/what-is-the-difference-between-parent-and-base-in-perl-5

(and up-vote for Alan)

Tiemen
Thank you for the link.
Alan Haggai Alavi
Thanks, that's perfect
aidan
+4  A: 

The typical use of @ISA is

package Foo;

require Bar;
our @ISA = qw/Bar/;

The base and parent pragmas both load the requested class and modify @ISA to include it:

package Foo;

use base qw/Bar/;

If you want multiple inheritance, you can supply more than one module to base or parent:

package Foo;

use parent qw/Bar Baz/; #@ISA is now ("Bar", "Baz");

The parent pragma is new as of Perl 5.10.1, but it is installable from CPAN if you have an older version of Perl. It was created because the base pragma had become difficult to maintain due to "cruft that had accumulated in it." You should not see a difference in the basic use between the two.

Chas. Owens
+1  A: 

from base's perldoc...

package Baz;

use base qw( Foo Bar );

is essentially equivalent to

package Baz;

BEGIN {
   require Foo;
   require Bar;
   push @ISA, qw(Foo Bar);
}

Personally, I use base.

spudly
The latest base.pm tells people to use parent, which is in 5.10.1. :)
brian d foy