|
From: Chris W. <la...@us...> - 2001-11-26 06:30:17
|
Update of /cvsroot/openinteract/OpenInteract/pkg/base_page/OpenInteract/Page
In directory usw-pr-cvs1:/tmp/cvs-serv15367/OpenInteract/Page
Added Files:
Http.pm
Log Message:
added a driver to load the page content from a URL
--- NEW FILE: Http.pm ---
package OpenInteract::Page::Http;
# $Id: Http.pm,v 1.1 2001/11/26 06:30:14 lachoy Exp $
use strict;
use HTTP::Request;
use LWP::UserAgent;
my ( $AGENT );
BEGIN {
$AGENT = LWP::UserAgent->new();
$AGENT->agent( "OpenInteract Requester " . $AGENT->agent );
}
sub load {
my ( $self ) = @_;
unless ( $self->{content_location} ) {
return "Cannot retrieve content -- no URL specified.";
}
unless ( $self->{content_location} =~ /^http/ ) {
return "Cannot retrieve content -- invalid URL specified.";
}
my $request = HTTP::Request->new(
GET => $self->{content_location} );
my $response = $AGENT->request( $request );
if ( $response->is_success ) {
my $content = $response->content;
$content =~ s|^.*<body||ism;
$content =~ s|</body>.*$||ism;
}
else {
return 'Cannot retrieve content -- code ' .
$response->code . ' returned.';
}
}
sub save {
my ( $self ) = @_;
warn "--Location $self->{location} cannot be saved, since it's ",
"using HTTP storage.\n";
return 1;
}
sub remove {
my ( $self ) = @_;
warn "--Location $self->{location} cannot be removed, since it's ",
"using HTTP storage.\n";
return 1;
}
1;
__END__
=pod
=head1 NAME
OpenInteract::Page::Http - Fetch page content from a URL
=head1 SYNOPSIS
my $page = $R->page->new({ storage => 'http',
content_location => 'http://slashdot.org/' });
print $page->content
=head1 DESCRIPTION
Retrieves content from a URL rather than the filesystem or database.
The URL is specified in the 'content_location' property of the page
object, and the 'storage' property is set to 'http'.
We strip everything before and including the <body> tag and everything
after and including the </body> tag.
=head1 METHODS
B<load( $page )>
Returns the content from the URL stored in the 'content_location'
property.
B<save( $page )>
Not implemented.
B<remove( $page )>
Not implemented.
=head1 BUGS
None known.
=head1 TO DO
Nothing known.
=head1 SEE ALSO
=head1 COPYRIGHT
Copyright (c) 2001 intes.net, inc.. All rights reserved.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 AUTHORS
Chris Winters <ch...@cw...>
=cut
|