diff options
author | franck cuny <franck@lumberjaph.net> | 2009-07-17 17:17:54 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2009-07-17 17:17:54 +0200 |
commit | ee4d87281ff498b5491e5ab06684379198ace86b (patch) | |
tree | e3503989bd7fc4eb8cf7669e6691c921f03a7448 /lib/MooseX/UserAgent/Paranoid.pm | |
parent | update (c) (diff) | |
download | moosex-useragent-ee4d87281ff498b5491e5ab06684379198ace86b.tar.gz |
up
Diffstat (limited to 'lib/MooseX/UserAgent/Paranoid.pm')
-rw-r--r-- | lib/MooseX/UserAgent/Paranoid.pm | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/lib/MooseX/UserAgent/Paranoid.pm b/lib/MooseX/UserAgent/Paranoid.pm index 61dab94..b33b157 100644 --- a/lib/MooseX/UserAgent/Paranoid.pm +++ b/lib/MooseX/UserAgent/Paranoid.pm @@ -1,32 +1,70 @@ package MooseX::UserAgent::Paranoid; -use URI; -use HTTP::Request; -use HTTP::Response; -use LWPx::ParanoidAgent; - use Moose::Role; with qw/ MooseX::UserAgent::Config MooseX::UserAgent::Content MooseX::UserAgent::Cache + MooseX::UserAgent::Generic /; has _LWPLIB => ( isa => 'Str', is => 'ro', default => 'LWPx::ParanoidAgent' ); -sub fetch { - my ( $self, $url ) = @_; +1; - my $req = HTTP::Request->new( GET => URI->new($url) ); +__END__ - $req->header( 'Accept-Encoding', 'gzip' ); - my $last_modified = $self->get_ua_cache($url); - $req->header( 'If-Modified-Since' => $last_modified ) - if $last_modified; +=head1 NAME - my $res = $self->agent->request($req); - $self->store_ua_cache( $url, $res ); - $res; -} +RTGI::Role::UserAgent::Paranoid - Fetch an url using LWPx::ParanoidAgent -1; +=head1 SYNOPSIS + + package Foo; + + use Moose; + with qw/MooseX::UserAgent::Paranoid/; + + has useragent_conf => ( + isa => 'HashRef', + default => sub { + { name => 'myownbot', }; + } + ); + + my $res = $self->fetch($url, $cache); + ... + my $content = $self->get_content($res); + +=head1 DESCRIPTION + +=head2 METHODS + +=over 4 + +=item B<fetch> + +This method will fetch a given URL. This method handle only the http +protocol. + +If there is a cache configuration, the url will be checked in the cache, +and if there is a match, a 304 HTTP code will be returned. + +Return a HTTP::Response object. + +=back + +=head1 BUGS AND LIMITATIONS + +=head1 AUTHOR + +franck cuny C<< <franck.cuny@rtgi.fr> >> + +=head1 LICENCE AND COPYRIGHT + +Copyright (c) 2009, RTGI +All rights reserved. +L<http://rtgi.fr/> + +This module is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. See L<perlartistic>. |