Ok I got desperate and decided to look at how Links SQL does it and so I'm trying this now:
# ------------------------------------------------------------------
#
my $pkg = shift;
my $callpkg = caller;
my @symbols = @_;
# Import requested vars.
foreach my $sym (@symbols) {
no strict 'refs';
CASE: {
($sym eq '$IN') and *{$callpkg . '::IN'} = \$IN, next;
($sym eq '$CFG') and *{$callpkg . '::CFG'} = \$CFG, next;
($sym eq '$DB') and *{$callpkg . '::DB'} = \$DB, next;
($sym eq '$TPL') and *{$callpkg . '::TPL'} = \$TPL, next;
($sym eq '$HTM') and *{$callpkg . '::HTM'} = \$HTM, next;
($sym eq '$LIB') and *{$callpkg . '::LIB'} = \$LIB, next;
die "Invalid symbol: $sym imported by $callpkg";
}
}
# Create variables requested.
my %symbols = map { $_ => 1 } @symbols;
init_vars(\%symbols);
}
Now, in the main script, wt.cgi this works great and I can use $CFG $DB etc....but it won't work in my modules.
Putting this:
use LoadMe qw/$CFG/;
print $CFG->{USER};
...in the main script works....putting the same in a module says "explicit package bla bla"
Any ideas please :(
Code:
sub import { # ------------------------------------------------------------------
#
my $pkg = shift;
my $callpkg = caller;
my @symbols = @_;
# Import requested vars.
foreach my $sym (@symbols) {
no strict 'refs';
CASE: {
($sym eq '$IN') and *{$callpkg . '::IN'} = \$IN, next;
($sym eq '$CFG') and *{$callpkg . '::CFG'} = \$CFG, next;
($sym eq '$DB') and *{$callpkg . '::DB'} = \$DB, next;
($sym eq '$TPL') and *{$callpkg . '::TPL'} = \$TPL, next;
($sym eq '$HTM') and *{$callpkg . '::HTM'} = \$HTM, next;
($sym eq '$LIB') and *{$callpkg . '::LIB'} = \$LIB, next;
die "Invalid symbol: $sym imported by $callpkg";
}
}
# Create variables requested.
my %symbols = map { $_ => 1 } @symbols;
init_vars(\%symbols);
}
Now, in the main script, wt.cgi this works great and I can use $CFG $DB etc....but it won't work in my modules.
Putting this:
use LoadMe qw/$CFG/;
print $CFG->{USER};
...in the main script works....putting the same in a module says "explicit package bla bla"
Any ideas please :(