Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: How relevant is the order of 'use's ?

by Krambambuli (Curate)
on Oct 20, 2016 at 13:58 UTC ( #1174365=note: print w/replies, xml ) Need Help??

in reply to Re: How relevant is the order of 'use's ?
in thread How relevant is the order of 'use's ?

yesss.... Your response, as well the previous one, gave the right direction.

The defined import function is *not* OK. Replacing it with something closer to what Exporter does seems to solve the problem:
package Demo2; sub import { #${[caller]->[0].'::'}{$_} = ${__PACKAGE__."::"}{$_} *{[caller]->[0].'::'.$_} = \&{__PACKAGE__."::$_"} foreach grep { not /^(ISA|isa|BEGIN|import|Dumper)$/ } keys %{__PACKAGE__."::"}; } use constant { SUCCESS => 0, }; 1;
Now I just have to understand how come that it works :)

Replies are listed 'Best First'.
Re^3: How relevant is the order of 'use's ?
by Eily (Monsignor) on Oct 20, 2016 at 14:27 UTC

    Actually I think you can do even simpler/easier to read:

    use Exporter; use base qw/Exporter/; our %constants; BEGIN { push @ISA, 'EXPORTER'; %constants = (SUCCESS => 1); @EXPORT = map "&$_", keys %constants; } use constant \%constants;
    Since I guess your goal is to export all the constants in Demo2 without having to provide the list of names twice. And with the & appended to each name, there's no risk of overwriting $SUCCESS;

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1174365]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2022-12-04 15:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found