SPUG: Inheritance

Brian Maher maherb at brimworks.com
Tue Oct 12 11:22:53 CDT 2004


I just used your code, added the 'use CLE2::Interface' to the  
CLE2::ProvisionerIF module and it seems to work now.  Be sure to end  
all your .pm modules with 1; (all perl modules must return true if they  
successfully load).  I think any problems that are requiring the  
@EXPORT_OK are all together different problems.  Be sure all your  
method calls are being called with either the package name or an object  
blessed to that package.  Simply putting a line like this in your code  
won't work:

   super_class_method();

Also be sure that all methods take a $self object as the first  
parameter (that is expected to be either a blessed reference or a  
package name.

Cheers,
-Brian

On Oct 12, 2004, at 8:10 AM, Dan Ebert wrote:

>
> I thought that if you were inheriting you didn't have to 'use' the base
> class.
>
> I tried just putting 'use CLE2::Interface' in the provisionerIF module  
> and
> that didn't work.  The only way I could get it to work is to put all  
> the
> methods in @EXPORT_OK in the CLE2::Interface and use CLE2::Interface
> qw(all the methods) in the CLE2::Provisioner.  I didn't think this was
> supposed to be necessary if the CLE2::Interface was in the @ISA array.  
>  It
> isn't described like this in the Camel book or in O'Reilly's 'Advanced
> Perl Programming'
>
> So, I got it to work, but I don't think I'm doing it the 'right' way.
>
> Dan.
> ----------------------------------------------------------
> Immigration is the sincerest form of flattery.
> 	- Unknown
> ----------------------------------------------------------
>
>
> On Mon, 11 Oct 2004, Umar Cheema wrote:
>
>> 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
>>
>
> _____________________________________________________________
> 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
>
>
--
Brian Maher >> Glory to God <<



More information about the spug-list mailing list