Doubt in perl basics use
it is somewhat similar to my other question Perl: Two packages in same file...
consider a perl script:
Script.pl
use INCLUDES;
INCLUDES.pm
package INCLUDES;
use Exporter;
############# MY DOUBT STARTS HERE ###############
use Module1;
use Module2;
##################################################
our @ISA = qw(Exporter);
our @EXPORT = qw();
sub import {
print 'INCLUDES imported to ' . caller . "\n";
}
Module1.pm
package Module1;
use strict;
use Exporter;
use INCLUDES; #####=> INCLUDES.pm 'use'd
our @ISA = qw(Exporter);
our @EXPORT = qw();
1;
Module2.pm
package Module2;
use strict;
use Exporter;
use INCLUDES; #####=> INCLUDES.pm 'use'd
our @ISA = qw(Exporter);
our @EXPORT = ();
1;
OUTPUT
D:\Do_analysis>Script.pl
INCLUDES imported to main
According to perl docs, use INCLUDES;
in Module1 & Module2 => BEGIN {require 'INCLUDES.pm'; 'INCLUDES'->import();}
. So, the import()
should be called in Module1.pm , Module2.pm also.
I would expect the output as something like below,
EXPECTED OUTPUT ??
D:\Do_analysis>Script.pl
INCLUDES imported to main
INCLUDES imported to Module1
INCLUDES imported to Module2
But why is the execution not as expected?
UPDATED
This is what I am trying to achieve, by having the INCLUDES.pm file.
Note that: PACKAGE2
might want to access PACKAGE3, PACKAGE4 etc. Instead of use
ing all the modules inside PACKAGE2
seperately, I would like to create a Library INCLUDES
and use
it in all other modules.
Is this approach valid? or recommendable?
I appreciate any idea about how to achieve this. Thanks!