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)

Replies are listed 'Best First'.
Re: LWP::Simple and Dancer2 function name collision
by Perlbotics (Archbishop) 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();