----- Original Message -----
From: Perrin Harkins <[EMAIL PROTECTED]>
Date: Friday, March 7, 2003 12:41 pm
Subject: Re: [Templates] Best equivalent to [% INCLUDE http://... %]

> [EMAIL PROTECTED] wrote:
> > Every report has a unique URL, so if I was able to say
> > [% INCLUDE 
> http://www.example.com/reports/run_report.cgi?report_id=A&view_id=B %],
> > it would make things very easy indeed.
> 
> Making a plugin to include the output of an HTTP request would be 
> simple, but not very efficient.  It would be better to write a 
> plugin 
> which runs the same code that the HTTP request does and includes 
> the 
> output.  This may require you to restructure your code though.

I'm not sure where to start on that one, but I did manage to write a very simple 
plugin that does what I want.  I've attached it for you're viewing (dis?)pleasure.  
Feedback is welcome.

Doug Gorley | [EMAIL PROTECTED]

# This file is -*-Perl-*-.
#==========================================================================
#
# Template::Plugin::WebFetch
#
# DESCRIPTION
#   Template Toolkit plugin for retrieving web content.
#
# AUTHOR
#   Doug Gorley <[EMAIL PROTECTED]>
#
# COPYRIGHT
#   This module is free software; you can redistribute it and/or
#   modify it under the same terms as Perl itself.
#
# REVISION
#   0.0.1
#
#==========================================================================

package Template::Plugin::WebFetch ;
require 5.006 ;

use strict ;
use vars qw( $VERSION ) ;
use base qw( Template::Plugin ) ;

use LWP::UserAgent ;

sub load { return $_[0] }

sub new {
    my $class = shift ;
    my $ua = LWP::UserAgent->new( env_proxy  => 1,
                                  keep_alive => 1,
                                  timeout    => 30 );
    bless { _UA => $ua }, $class ;
}

sub fetch { return $_[0]->{ _UA }->get( $_[1] )->content }

Reply via email to