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.
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.
I think you should use the parent
pragma instead of base
as has been suggested in perldoc base
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With