SPUG: Inheritance

Don Shanks me at donshanks.com
Mon Oct 11 17:23:51 CDT 2004


You could just

use base('CLE2::Interface');

and forget about the use CLE2* line and the @ISA push altogether.

--Don


<quote who="Umar Cheema">
> In your package CLE2::ProvisionerIF, you seem to be missing this line:
>
> use CLE2::Interface;
>
>
>
>
>
> On Mon, 11 Oct 2004, Dan Ebert wrote:
>
>>
>> I am trying to create a series of modules which inherit from a base
>> class.
>> The base class looks like this:
>>
>> package CLE2::Interface;
>> ###############################################################################
>> use strict;
>> ###############################################################################
>> use vars qw(@ISA @EXPORT_OK $VERSION $err);
>> require Exporter;
>> $VERSION = '0.01';
>> @ISA = qw(Exporter);
>> ###############################################################################
>> zub allocate {
>>     my $invocant = shift;
>>     my $class    = ref($invocant) || $invocant; # Object or class name
>>     my $interface = bless { @_ }, $class;
>>     return $interface;
>> }
>> ###############################################################################
>>
>> and is saved to a file: CLE2/Interface.pm
>>
>> I have another module, CLE2/ProvisionerIF.pm
>>
>> package CLE2::ProvisionerIF;
>> ###############################################################################
>> use strict;
>> ###############################################################################
>> use vars qw(@ISA @EXPORT_OK $VERSION $err);
>> require Exporter;
>> $VERSION = '0.01';
>> @ISA = ("CLE2::Interface"); # I'v also tried @ISA = ("Interface");
>> ###############################################################################
>> zub new {
>>     my $pkg = shift;
>>     return $pkg->allocate(@_);
>> }
>> ###############################################################################
>>
>> I have a script which uses CLE2::ProvisionerIF:
>>
>> use CLE2::ProvisionerIF;
>>
>> my $provisioner = new CLE2::ProvisionerIF( %param_hash );
>>
>> I'm getting an error, "Can't locate object method "allocate" via package
>> "CLE2::ProvisionerIF" at CLE2/ProvisionerIF.pm line 20."  (line 20 is
>> the
>> line with  "return $pkg->allocate(@_)")
>>
>> I must be missing something simple, but I can't put my finger on it.
>>
>> Any help is appreciated.
>>
>> Thanks,
>>
>> Dan.
>> ----------------------------------------------------------
>> Immigration is the sincerest form of flattery.
>> 	- Unknown
>> ----------------------------------------------------------
>>
>>
>> _____________________________________________________________
>> Seattle Perl Users Group Mailing List
>> POST TO: spug-list at mail.pm.org  http://spugwiki.perlocity.org
>> ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
>> MEETINGS: 3rd Tuesdays, Location Unknown
>> WEB PAGE: http://www.seattleperl.org
>>
>
>
>
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at mail.pm.org  http://spugwiki.perlocity.org
> ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, Location Unknown
> WEB PAGE: http://www.seattleperl.org
>



More information about the spug-list mailing list