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

sawyer x xsawyerx at gmail.com
Sun May 15 09:11:20 CEST 2011


Brian++ !

Also, you could ask LWP::Simple to *not* export get()or anything else.
>>>
    use LWP::Simple ();

You can then ask to get LWP::Simple's get() using:
>>>
    LWP::Simple::get(...);

On Sun, May 15, 2011 at 4:47 AM, Brian E. Lozier <brian at massassi.com> wrote:

> 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();
>
> $ua->agent("Some/string");
>
> 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
> >
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20110515/3240570c/attachment.htm>


More information about the Dancer-users mailing list