using LWP::Simple with Dancer
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? Puneet.
On Sat, May 14, 2011 at 6:29 PM, Mr. Puneet Kishor <punk.kish@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@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
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@massassi.com> wrote:
On Sat, May 14, 2011 at 6:29 PM, Mr. Puneet Kishor <punk.kish@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@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
participants (3)
-
Brian E. Lozier -
Mr. Puneet Kishor -
sawyer x