HTML::Feature::Fetcher - Fetch a HTML document.


HTML-Feature documentation Contained in the HTML-Feature distribution.

Index


Code Index:

NAME

Top

HTML::Feature::Fetcher - Fetch a HTML document.

SYNOPSIS

Top

  use HTML::Feature::Fetcher;

  my $fetcher       = HTML::Feature::Fetch->new;
  my $http_response = $fetcher->request($url);

DESCRIPTION

Top

This is a wrapper LWP::UserAgent.

METHODS

Top

new

request

AUTHOR

Top

Takeshi Miki <miki@cpan.org>

LICENSE

Top

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Top


HTML-Feature documentation Contained in the HTML-Feature distribution.

package HTML::Feature::Fetcher;
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request;
use base qw(HTML::Feature::Base);

__PACKAGE__->mk_accessors($_) for qw(fetcher);

sub new {
    my $class = shift;
    my $self  = $class->SUPER::new(@_);
    $self->_setup;
    return $self;
}

sub _setup {
    my $self    = shift;
    my $c       = $self->context;
    my $fetcher = LWP::UserAgent->new;
    my $config  = $c->config;
    if ( $config->{user_agent} ) {
        $fetcher->user_agent( $config->{user_agent} );
    }
    if ( $config->{http_proxy} ) {
        $fetcher->proxy( ['http'], $config->{http_proxy} );
    }
    else {
        $fetcher->env_proxy;
    }
    if ( $config->{timeout} ) {
        $fetcher->timeout( $config->{timeout} );
    use Data::Dumper;
        print Dumper $fetcher;
    }
    $self->fetcher($fetcher);
}

sub request {
    my $self     = shift;
    my $url      = shift;
    my $request  = HTTP::Request->new( GET => $url );
    my $response = $self->fetcher->request($request);
    return $response;
}

1;
__END__