[Dancer-users] using LWP::Simple with Dancer

Brian E. Lozier brian at massassi.com
Sun May 15 03:47:49 CEST 2011

On Sat, May 14, 2011 at 6:29 PM, Mr. Puneet Kishor <punk.kish at gmail.com> wrote:
> There is perhaps another way, probably very simple, but I am drawing a blank. In my web app, I want to download the content at a few different URIs, strip them off the tags, and store the text for further processing. A simple command line script uses LWP::Simple to download the content, then HTTP::Strip removes the tags. This script works from the command line, But, within Dancer, I get a 'get is redefined' error. How can I implement such functionality within Dancer?

This is because LWP::Simple exports "get" and Dancer defines "get" as
well.  Two different functions with the same name can't be in the same
namespace.  LWP::Simple is a very simple layer around LWP::UserAgent.
I recommend using LWP::UserAgent directly as it doesn't export a
method called "get."

use LWP::UserAgent;

my $ua = LWP::UserAgent->new();


my $response = $ua->get($url_to_get);

my $content;

if($response->is_success()) {
    $content = $response->decoded_content();
else {
    # no dice

You could also try not to import LWP::Simple's get function and then
use a fully qualified function call.  I'm not sure this will work if
the module wasn't programmed this way.

use LWP::Simple (); # Import nothing

my $content = LWP::Simple::get($url_to_get);

> Puneet.
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users

More information about the Dancer-users mailing list