in reply to Re: Export and use different package in module
in thread Export and use different package in module
I'll try to post it, see if it makes more sense.
main
use strict; use warnings; use File::Basename qw(dirname); use Cwd qw(abs_path); use lib dirname(dirname abs_path $0); use Library; print STDOUT $hash{"key"} . "\n"; exit 0;
this works
Library.pm
package Library; use strict; use warnings; use Exporter qw(import); our @EXPORT = qw( %hash ); our %hash = ( "key" => "Hello world!" ); 1;
these don't work
Library2.pm
package Library2; use strict; use warnings; our @EXPORT = qw( return_string ); sub return_string { return "Hello embedded library"; }
Library.pm
package Library; use strict; use warnings; use Exporter qw(import); our @EXPORT = qw( %hash ); use File::Basename qw(dirname); use Cwd qw(abs_path); use lib dirname(dirname abs_path $0); use Library2; package Library2; our %hash = ( "key" => return_string() ); 1;
I can understand it looks like the namespaces are overlapping, but the definition isn't exported even with 'our'. Just fiddled around with it, I can do our %hash = (); BEFORE the package othernamespace, and export the modification. That'll work for my case, but I'd rather not have 3-4 places I need to put the hash instead of just export and our. It seems my gripe is that a variable declared before the package othernamespace trickles down, but a variable declared after the package othernamespace doesn't trickle up when it's the same file, even though there's no complaint about the definition in another namespace and not in the original.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Export and use different package in module
by haukex (Archbishop) on Feb 22, 2019 at 20:38 UTC | |
by chenhonkhonk (Acolyte) on Feb 22, 2019 at 20:54 UTC | |
by haukex (Archbishop) on Feb 22, 2019 at 21:11 UTC | |
by chenhonkhonk (Acolyte) on Feb 22, 2019 at 22:27 UTC | |
by haukex (Archbishop) on Feb 22, 2019 at 23:29 UTC | |
|