in reply to Problem in using Exporter

Hi, I'm not sure where your "problem" is. You are missing an error not getting one.

The solution is, I think, that Perl looks up the function names at run-time not at compile-time! The call to first_method() is compiled in but where/what this function exactly is is only interpreted at run-time, which isn't executed when using the -c switch.

Also your code is incomplete because you are missing a main file which uses this two modules:

#!/usr/bin/perl use warnings; use strict; use Second; Second::second_method();
When I run this script I get the following error:
Inside second_method Undefined subroutine &Second::first_method called at Second.pm line 11 +.
But I figured out that you missed the following line in First.pm:
our @ISA = qw(Exporter);
Otherwise nothing will be exported.

Replies are listed 'Best First'.
Re^2: Problem in using Exporter
by praveenkumar (Novice) on Apr 22, 2008 at 06:05 UTC
    The import() method in Exporter class is executed at the compile-time by the use compiler directive. So, when the compiler sees use First qw(first_method) the Exporter class should look at EXPORT or EXPORT_OK of First and check for the method first_method. If it is not there in any of the EXPORT lists then it should throw an error. But it is not....