Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by Anonymous Monk
on Jul 29, 2014 at 22:15 UTC ( #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? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2022-05-23 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?