Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Can locate when called directly, but can't when in @ISA

by Phemto (Acolyte)
on Oct 05, 2007 at 11:02 UTC ( #642892=perlquestion: print w/replies, xml ) Need Help??

Phemto has asked for the wisdom of the Perl Monks concerning the following question:

Hi there. I have two package files: and

Both are located in the same directory, and I'm using "use lib" to point to that directory. contains the code

use lib "...module_directory..."; $VERSION = 0.01; @ISA = qw(Exporter Cloud);
My main program contains the same use lib line. When I "use Cloud" from the program it finds it just fine, but when I "use Lens" I get: Can't locate package Cloud for @Lens::ISA at... There must be something obvious that I'm missing. Thinking the "use lib" line wasn't doing what I thought it was, I've also tried moving the files to my current directory so they'd be in @INC, but that didn't fix it.

I'm losing my hair fast enough as it is without this making me pull it out :)

Replies are listed 'Best First'.
Re: Can locate when called directly, but can't when in @ISA
by Gilimanjaro (Hermit) on Oct 05, 2007 at 11:44 UTC

    @ISA doesn't magically load the classes you're inheriting from. The child class Lens still needs to load (use) the parent class Cloud.

    Also, you may want to 'use strict' and 'use warnings' and prefix @ISA with 'our'.

    You can do both by using the 'base' pragma:

    use base qw(Exporter Cloud);

      You can do both by using the 'base' pragma

      ... but before switching to "use base", the OP may want to form his own opinion about the objections a couple of renowned monks have had in the thread 'base' versus @ISA, why?.

        That was helpful information, but I am no an OOP super freak either. For my needs, use base 'parent'; works perfectly and I am able to easily augment the parent's creation class with out any problems:
        use base 'My::Parent::Class'; sub new { my $pkg = shift; my $self = $pkg->SUPER::new(@_); return $self; }
      Wohoo! Was that a rookie mistake, or what? Thanks! Now I just need to figure out why some of my modules aren't returning true values, but that's a separate issue. And yes, I have a "1;" at the end. :->

      Thanks again.

Re: Can locate when called directly, but can't when in @ISA
by rhesa (Vicar) on Oct 05, 2007 at 11:40 UTC
    Are you saying that Lens->isa('Cloud') *and* Cloud->isa('Lens')? You might want to reconsider that!
      Sorry for the confusion. inherits from, but not the other way around. I used "use Cloud" from the calling program (separate file) to test that could be found in @INC, which it can. But when I try "use Lens" instead, it finds Lens, but then Lens can't find Cloud.

      Does @ISA not use @INC to find modules? That would be weird. Is this a poor system administration issue? As the SysAdmin, I could easily believe it.

Re: Can locate when called directly, but can't when in @ISA
by lyklev (Pilgrim) on Oct 07, 2007 at 14:19 UTC
    Check if both Lens and Cloud have a packagedeclaration. Blow are my working code snippets:

    Main program:

    #!/usr/bin/perl use strict; use warnings; use lib '/home/me/project/temp'; use Lens;

    In '/home/me/project/temp' are

    package Cloud; use strict; use warnings; 1;


    package Lens; use strict; use warnings; use lib '/home/me/project/temp'; use Cloud; our @ISA = qw(Exporter Cloud); 1;

    Apart from the recommended strict and warnings, all</code> is necessary.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://642892]
Approved by svenXY
Front-paged by Corion
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2023-12-03 01:10 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (20 votes). Check out past polls.