Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by Anonymous Monk
on Jul 29, 2014 at 22:15 UTC ( [id://1095525]=note: print w/replies, xml ) Need Help??


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

Import::Into seems to do what you want.
  • Comment on Re: Including modules and pragmas in caller's scope via use

Replies are listed 'Best First'.
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

    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.)

      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://1095525]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-20 15:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found