Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

LWP::Simple and Dancer2 function name collision (solved)

by davies (Parson)
on Jan 05, 2014 at 17:13 UTC ( #1069394=perlquestion: print w/replies, xml ) Need Help??
davies has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to write some code using LWP::Simple and Dancer2. This complains about each of them exporting "get" into the main:: namespace. LWP's documentation is silent about this, while Dancer's is, to me at least, incomprehensible. It says:

Import gets called when you use Dancer2. You can specify import options giving you control over the keywords that will be imported into your webapp and other things: use Dancer2 ':script'; Import Options ":script" Do not process arguments.

Googling has got me nowhere. Can anyone suggest some reading I might usefully do?


John Davies

Update: Thanks, Perlbotics. Your solution works perfectly.
  • Comment on LWP::Simple and Dancer2 function name collision (solved)

Replies are listed 'Best First'.
Re: LWP::Simple and Dancer2 function name collision
by Perlbotics (Canon) on Jan 05, 2014 at 17:33 UTC

    One approach would be to avoid importing symbols from one of the modules that cause the collision. I.e., you could avoid importing symbols from LWP::Simple like so:

    use LWP::Simple (); # () means: do not import any symbols into curre +nt package
    (see use) and then invoke the sub using explicit package name:
    my $res = LWP::Simple::get('');
    When dealing with bigger projects, this approach avoids the name-clashes and removes ambiguity. Using an OO-interface would be another solution if feasible(wrapper?)/available.

Re: LWP::Simple and Dancer2 function name collision ( Exporter )
by Anonymous Monk on Jan 05, 2014 at 17:46 UTC

    I remember when Exportering mechanisms were major parts of the documentation of modules, go figure :/

    use LWP::Simple qw/ $ua /; $ua->show_progress(1); if( $ua->get(..)->is_success ){ ... } $ua->post();

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1069394]
Approved by boftx
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-05-28 12:40 GMT
Find Nodes?
    Voting Booth?