in reply to Re: Variables in Common parent class
in thread Variables in Common parent class

I tried your program after moving the package code to different files, error from MyModule says undefined subroutine at SuperModule::new. Works only if SuperModule and MyModule are in same file.

How can I make it see the new from SuperModule.pm?

Replies are listed 'Best First'.
Re^3: Variables in Common parent class
by Athanasius (Archbishop) on Mar 14, 2013 at 12:24 UTC

    Organise the code like this:

    File main.pl:

    #! perl use strict; use warnings; use MyModule; use YourModule; # ... as before ...

    File SuperModule.pm:

    #! perl package SuperModule; # ... as before ... 1;

    File MyModule.pm:

    #! perl package MyModule; use strict; use warnings; use SuperModule; our @ISA = qw( SuperModule ); # ... as before ... 1;

    File YourModule.pm:

    #! perl package YourModule; use strict; use warnings; use SuperModule; our @ISA = qw( SuperModule ); # ... as before ... 1;

    Note that a standalone module (i.e., a file with a .pm extension) must return true on success. Hence the common practice of ending each module with 1; on a line by itself. See Perl Modules in perlmod.

    This scheme assumes that the four files are in the same directory. If they’re not, you will need to investigate the use lib pragma. See lib.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,