Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Including modules and pragmas in caller's scope via use

by wanna_code_perl (Friar)
on Jul 30, 2014 at 11:48 UTC ( [id://1095603]=note: print w/replies, xml ) Need Help??


in reply to Re: Including modules and pragmas in caller's scope via use
in thread Including modules and pragmas in caller's scope via use

Indeed, I think it does. I had a chance to play around with it, and after a minor disagreement with autodie, I got it to do everything I needed.

For anyone reading this later on with the same question: the Import::Into docs make reference to autodie being difficult, but (to me, anyway) were a little vague on how to fix that. Almost all examples in the documentation use the following format:

my $target = scalar caller; $package->import::into($target, @arguments);

However, autodie doesn't work with the above approach, but they say "Some exporting modules, such as autodie or strictures, care about the filename they are being imported to.". But it took just a bit more effort than just using the alternate hashref syntax. With autodie, what worked the best for me was this:

my ($package, $filename, $line) = caller; autodie->import::into({ package => $package, filename => $filename, line => $line });

(Note both of these examples would go into your module's import sub, as usual with Import::Into.)

Replies are listed 'Best First'.
Re^3: Including modules and pragmas in caller's scope via use
by Haarg (Priest) on Aug 01, 2014 at 22:34 UTC
    The documentation could use some improvements for this. The better syntax would be:
    autodie->import::into(1);
    This imports to the package/file/line at caller level 1, which matches what you are doing manually.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 17:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found