in reply to Overriding module-internal calls

Untested.
{ my $real_meth = \&LWP::UserAgent::agent; local *LWP::UserAgent::agent = sub { $_[1] = "Camel Power 3.14.15" if $_[1] =~ /XML::RSS/; goto &$real_meth; }; $rss_object->rss_uri('http://foo/bar/index.rss'); }
The much safer alternative is to simply fetch the RSS yourself and feed it to the class as a string.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Overriding module-internal calls
by hacker (Priest) on Apr 22, 2003 at 12:08 UTC
    This seems to fix it, though is a bit slow, having to load up LWP::UserAgent to do the work:
    use strict; use warnings; use XML::RSS::Tools; use LWP::UserAgent; my $rss_feed = XML::RSS::Tools->new; my $ua = LWP::UserAgent->new; $ua->agent('Camel Power 3.14.15 [rss])'); my $rss = "http://www.perl.com/pace/news.rss"; my $request = HTTP::Request->new(GET => $rss); my $response = $ua->request($request); my $status = $response->status_line; my %errors = ('500'=>'Bad hostname supplied', '501'=>'Protocol not supported', '404'=>'URL not found', '403'=>'URL forbidden', '401'=>'Authorization failed', '400'=>'Bad request found', '302'=>'Redirected URL' ); ($status) = ($status =~ /(\d+)/); if (defined($errors{$status})) { die "ERROR: $errors{$status}\n"; } else { my $content = $response->content; $rss_feed->rss_string($content); $rss_feed->xsl_file('rss.xsl'); $rss_feed->transform; print $rss_feed->as_string; }

    I'll hit it with benchmark and see if maybe one of the other feching modules can do the same thing faster. Any suggestions on alternate modules that can do the same thing? What I require is:

    1. Providing a custom UserAgent string
    2. Being able to do HEAD and GET on the URI
    3. Having a proper status_line come back for error trapping

      I'll hit it with benchmark and see if maybe one of the other feching modules can do the same thing faster.

      The speed overhead of ANY way to get the file, even if you fork curl for it, is absolutely irrelevant compared to the overhead of actually requesting the document and waiting for and getting its headers and body.

      Juerd
      - http://juerd.nl/
      - spamcollector_perlmonks@juerd.nl (do not use).
      

Re: Overriding module-internal calls
by Anonymous Monk on Apr 22, 2003 at 11:13 UTC
    Nada, same story, and gives me:
    "iC-XML::RSS::Tools/0.09 libwww-perl/5.69 (linux)"

    There must be some way to do this.. thanks for the suggestion though.

      As I said (and hacker implemented) - the safe, sane and solid way would be to just fetch the document yourself and feed it to XML::RSS::Tools as a string.

      Makeshifts last the longest.