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

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

by davies (Vicar)
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?

Regards,

John Davies

Update: Thanks, Perlbotics. Your solution works perfectly.

Comment on LWP::Simple and Dancer2 function name collision (solved)
Re: LWP::Simple and Dancer2 function name collision
by Perlbotics (Abbot) 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('http://www.example.com');
    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1069394]
Approved by boftx
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-09-16 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (155 votes), past polls