SPUG: Inheritance

Dan Ebert mathin at mathin.com
Tue Oct 12 10:10:16 CDT 2004


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
>



More information about the spug-list mailing list