Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

How do I use @ISA and use strict at the same time?

by thoglette (Scribe)
on Jun 05, 2001 at 08:45 UTC ( [id://85738]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

thoglette has asked for the wisdom of the Perl Monks concerning the following question: (object-oriented programming)

By default (5.004_02) adding
use strict;
causes the usual inheritance line of
@ISA = ("InheritedClass");
to fail for not being fully declared.
Trying local and my don't work - when running Perl complains Can't locate object method "new" via package

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do I use @ISA and use strict at the same time?
by davorg (Chancellor) on Jun 05, 2001 at 08:48 UTC
    use vars qw(@ISA);
Re: How do I use @ISA and use strict at the same time?
by Vynce (Friar) on Jun 05, 2001 at 09:45 UTC

    TIMTOWTDI:

    use strict; package Question::Loaded; use vars ('@ISA'); @ISA = ('Question');
    or
    package Question::Open; @ISA = ('Question'); use strict;
    or
    package Question::MillionDollar; use strict; our @ISA = ('Question'); # if (perl -v >= 5.6)
    and there are other ways, too. it's a matter of style.

    Edit by tye: Note that use strict can appear before the package line but that putting use vars before the package line will cause the file to fail to compile while putting our before the package line will not work in less obvious ways.

Re: How do I use @ISA and use strict at the same time?
by Anonymous Monk on Jun 05, 2001 at 14:05 UTC
    I think the best is
    package Question; @Question::ISA=("Another");
      Another way is to use vars @ISA, this makes the package a little more portable inside of a source tree.
      package Question;
      
      use strict;
      use vars qw( @ISA );
      
      @ISA = ( "Another" );
Re: How do I use @ISA and use strict at the same time?
by merlyn (Sage) on Jun 05, 2001 at 14:38 UTC
    If the parent class is in a separate file, consider using base.
Re: How do I use @ISA and use strict at the same time?
by cpousset (Initiate) on Jul 12, 2001 at 14:53 UTC
    No Problem!
    use strict; package InheritedClass; # ... stuff for InheritedClass package NewClass; @NewClass::ISA = ("InheritedClass");
    Strict was kvetching about @ISA, which is actually a class variable within NewClass.

    Originally posted as a Categorized Answer.

Re: How do I use @ISA and use strict at the same time?
by Narveson (Chaplain) on Jan 23, 2008 at 11:49 UTC
    use strict; package Wombat; use base 'Marsupial';
    See Conway, Perl Best Practices, chapter 16: Class Hierarchies, Inheritance.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://85738]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.