SYNOPSIS

 use aliased 'HTML::HTML5::Parser::UA';

 my $response = UA->get($url);
 die unless $response->{success};

 print $response->{decoded_content};

DESCRIPTION

This is a simple wrapper around HTTP::Tiny and LWP::UserAgent to smooth out the \s-1API\s0 differences between them. It only supports bog standard \*(C`get($url)\*(C' requests.

If LWP::UserAgent is already in memory, this module will use that.

If LWP::UserAgent is not in memory, then this module will use HTTP::Tiny (or direct filesystem access for \*(L"file://\*(R" URLs).

If LWP::UserAgent is not in memory, and you attempt to request a \s-1URL\s0 that HTTP::Tiny cannot handle (e.g. an \*(L"ftp://\*(R" \s-1URL\s0), then this module will load LWP::UserAgent and die if it cannot be loaded (e.g. is not installed).

HTML::HTML5::Parser::UA is used by the \*(C`parse_file\*(C' method of HTML::HTML5::Parser.

Class Method

Gets the \s-1URL\s0 and returns a hashref similar to HTTP::Tiny's hashrefs, but with an additional \*(C`decoded_content\*(C' key, which contains the response body, decoded into a Perl character string (not a byte string). If $ua is given (it's optional), then this user agent will be used to perform the actual request. Must be undef or an LWP::UserAgent object (or a subclass) or an HTTP::Tiny object (or a subclass).

Package Variable

If true, avoids using LWP::UserAgent.

MOTIVATION

LWP::UserAgent is a good piece of software but it has a dependency on HTML::Parser. HTML::Parser is only used to provide one fairly esoteric feature, which this package doesn't make use of. (It's the \*(C`parse_head\*(C' option.)

Because of that, I don't especially want HTML::HTML5::Parser to have a dependency on LWP::UserAgent. Hence this module.

RELATED TO HTML::HTML5::Parser::UA…

HTML::HTML5::Parser.

AUTHOR

Toby Inkster, <[email protected]>

COPYRIGHT AND LICENSE

Copyright (C) 2012 by Toby Inkster

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

DISCLAIMER OF WARRANTIES

\s-1THIS\s0 \s-1PACKAGE\s0 \s-1IS\s0 \s-1PROVIDED\s0 \*(L"\s-1AS\s0 \s-1IS\s0\*(R" \s-1AND\s0 \s-1WITHOUT\s0 \s-1ANY\s0 \s-1EXPRESS\s0 \s-1OR\s0 \s-1IMPLIED\s0 \s-1WARRANTIES\s0, \s-1INCLUDING\s0, \s-1WITHOUT\s0 \s-1LIMITATION\s0, \s-1THE\s0 \s-1IMPLIED\s0 \s-1WARRANTIES\s0 \s-1OF\s0 \s-1MERCHANTIBILITY\s0 \s-1AND\s0 \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0.