| 1 | package HTML::HTML5::Parser::UA; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | $HTML::HTML5::Parser::UA::AUTHORITY = 'cpan:TOBYINK'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | $HTML::HTML5::Parser::UA::VERSION = '0.991'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Encode qw(decode); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use URI::file; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | our $NO_LWP = '0'; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | sub get | ||||||||||||||||||||||||||||||||||||||||||
| 19 | { | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | ▶ | my ($class, $uri, $ua) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=9 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 8 | ▶ | if (ref $ua and $ua->isa('HTTP::Tiny') and $uri =~ /^https?:/i) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $ua and $ua->isa("HTTP::Tiny") and $uri =~ /^https?:/i
ref $ua and $ua->isa("HTTP::Tiny")
MC/DC0%0/3
ref $ua and $ua->isa("HTTP::Tiny") and $uri =~ /^https?:/i
ref $ua
$ua->isa("HTTP::Tiny")
$uri =~ /^https?:/i
Truth table25%1/4
A and B and C
A= ref $uaB= $ua->isa("HTTP::Tiny")C= $uri =~ /^https?:/i
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | { goto \&_get_tiny } | |||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | if (ref $ua and $ua->isa('LWP::UserAgent')) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $ua and $ua->isa("LWP::UserAgent")
MC/DC0%0/2
ref $ua and $ua->isa("LWP::UserAgent")
ref $ua
$ua->isa("LWP::UserAgent")
Truth table33%1/3
A and B
A= ref $uaB= $ua->isa("LWP::UserAgent")
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | { goto \&_get_lwp } | |||||||||||||||||||||||||||||||||||||||||
| 26 | 8 | ▶ | if (UNIVERSAL::can('LWP::UserAgent', 'can') and not $NO_LWP) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
UNIVERSAL::can("LWP::UserAgent", "can") and not $HTML::HTML5::Parser::UA::NO_LWP
MC/DC50%1/2
UNIVERSAL::can("LWP::UserAgent", "can") and not $HTML::HTML5::Parser::UA::NO_LWP
UNIVERSAL::can("LWP::UserAgent", "can")
not $HTML::HTML5::Parser::UA::NO_LWP
Truth table66%2/3
A and not(B)
A= UNIVERSAL::can("LWP::UserAgent", "can")B= not $HTML::HTML5::Parser::UA::NO_LWP
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | { goto \&_get_lwp } | |||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | if ($uri =~ /^file:/i) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | { goto \&_get_fs } | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | goto \&_get_tiny; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | sub _get_lwp | ||||||||||||||||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | eval "require LWP::UserAgent; 1" | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_lwp: called CC=3 SCAR=12.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | Carp::croak("could not load LWP::UserAgent"); | |||||||||||||||||||||||||||||||||||||||||
| 40 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | my ($class, $uri, $ua) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 5 | ▶ | $ua ||= LWP::UserAgent->new( | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$ua ||= "LWP::UserAgent"->new("agent", sprintf("%s/%s ", "HTML::HTML5::Parser", "HTML::HTML5::Parser"->VERSION), "default_headers", "HTTP::Headers"->new("Accept", "text/html, application/xhtml+xml;q=0.9, application/xml;q=0.1, text/xml;q=0.1"), "parse_head", 0)
MC/DC0%0/2
$ua ||= "LWP::UserAgent"->new("agent", sprintf("%s/%s ", "HTML::HTML5::Parser", "HTML::HTML5::Parser"->VERSION), "default_headers", "HTTP::Headers"->new("Accept", "text/html, application/xhtml+xml;q=0.9, application/xml;q=0.1, text/xml;q=0.1"), "parse_head", 0)
$ua
"LWP::UserAgent"->new("agent", sprintf("%s/%s ", "HTML::HTML5::Parser", "HTML::HTML5::Parser"->VERSION), "default_headers", "HTTP::Headers"->new("Accept", "text/html, application/xhtml+xml;q=0.9, application/xml;q=0.1, text/xml;q=0.1"), "parse_head", 0)
Truth table33%1/3
A ||= B
A= $uaB= "LWP::UserAgent"->new("agent", sprintf("%s/%s ", "HTML::HTML5::Parser", "HTML::HTML5::Parser"->VERSION), "default_headers", "HTTP::Headers"->new("Accept", "text/html, application/xhtml+xml;q=0.9, application/xml;q=0.1, text/xml;q=0.1"), "parse_head", 0)
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | agent => sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 46 | "%s/%s ", | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 'HTML::HTML5::Parser', | ||||||||||||||||||||||||||||||||||||||||||
| 48 | HTML::HTML5::Parser->VERSION, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 50 | default_headers => HTTP::Headers->new( | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 'Accept' => join q(, ) => qw( | ||||||||||||||||||||||||||||||||||||||||||
| 52 | text/html | ||||||||||||||||||||||||||||||||||||||||||
| 53 | application/xhtml+xml;q=0.9 | ||||||||||||||||||||||||||||||||||||||||||
| 54 | application/xml;q=0.1 | ||||||||||||||||||||||||||||||||||||||||||
| 55 | text/xml;q=0.1 | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 58 | parse_head => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | my $response = $ua->get($uri); | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | my $h = $response->headers; | |||||||||||||||||||||||||||||||||||||||||
| 64 | my %header_hash = | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | map { lc($_) => $h->header($_); } | |||||||||||||||||||||||||||||||||||||||||
| 66 | $h->header_field_names; | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | return +{ | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | success => $response->is_success, | |||||||||||||||||||||||||||||||||||||||||
| 70 | status => $response->code, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | reason => $response->message, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | headers => \%header_hash, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | content => $response->content, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | decoded_content => $response->decoded_content, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | sub _get_tiny | ||||||||||||||||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | ▶ | my ($class, $uri, $ua) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_tiny: called CC=4 SCAR=16.8
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | $ua ||= HTTP::Tiny->new( | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$ua ||= "HTTP::Tiny"->new("agent", sprintf("%s/%s", "HTML::HTML5::Parser", "HTML::HTML5::Parser"->VERSION), "default_headers", {"Accept", "text/html, application/xhtml+xml;q=0.9, application/xml;q=0.1, text/xml;q=0.1"})
MC/DC0%0/2
$ua ||= "HTTP::Tiny"->new("agent", sprintf("%s/%s", "HTML::HTML5::Parser", "HTML::HTML5::Parser"->VERSION), "default_headers", {"Accept", "text/html, application/xhtml+xml;q=0.9, application/xml;q=0.1, text/xml;q=0.1"})
$ua
"HTTP::Tiny"->new("agent", sprintf("%s/%s", "HTML::HTML5::Parser", "HTML::HTML5::Parser"->VERSION), "default_headers", {"Accept", "text/html, application/xhtml+xml;q=0.9, application/xml;q=0.1, text/xml;q=0.1"})
Truth table33%1/3
A ||= B
A= $uaB= "HTTP::Tiny"->new("agent", sprintf("%s/%s", "HTML::HTML5::Parser", "HTML::HTML5::Parser"->VERSION), "default_headers", {"Accept", "text/html, application/xhtml+xml;q=0.9, application/xml;q=0.1, text/xml;q=0.1"})
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | agent => sprintf("%s/%s", 'HTML::HTML5::Parser', HTML::HTML5::Parser->VERSION), | ||||||||||||||||||||||||||||||||||||||||||
| 84 | default_headers => +{ | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 'Accept' => join(q(, ) => qw( | ||||||||||||||||||||||||||||||||||||||||||
| 86 | text/html | ||||||||||||||||||||||||||||||||||||||||||
| 87 | application/xhtml+xml;q=0.9 | ||||||||||||||||||||||||||||||||||||||||||
| 88 | application/xml;q=0.1 | ||||||||||||||||||||||||||||||||||||||||||
| 89 | text/xml;q=0.1 | ||||||||||||||||||||||||||||||||||||||||||
| 90 | )), | ||||||||||||||||||||||||||||||||||||||||||
| 91 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | my $response = $ua->get($uri); | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | ▶ | if ($response->{headers}{'content-type'} =~ /charset=(\S+)/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | (my $encoding = $1) =~ s/["']//g; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $response->{decoded_content} = eval { | |||||||||||||||||||||||||||||||||||||||||
| 100 | decode($encoding, $response->{content}) | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | $response->{decoded_content} = $response->{content} | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | ▶ | unless defined $response->{decoded_content}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | return $response; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | sub _get_fs | ||||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_fs: called CC=13 SCAR=34.5
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | ▶ | my ($uri) = map { ref() ? $_ : URI->new($_) } @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | my $file = $uri->file; | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | my ($status, $reason, $content, $content_type) = do { | |||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | ▶ | if (not -e $file) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | { (404 => 'Not Found', 'File not found.', 'text/plain') } | |||||||||||||||||||||||||||||||||||||||||
| 118 | elsif (not -r $file) | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | { (403 => 'Forbidden', 'File not readable by effective guid.', 'text/plain') } | |||||||||||||||||||||||||||||||||||||||||
| 120 | else | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | { (200 => 'OK') } | |||||||||||||||||||||||||||||||||||||||||
| 122 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | $content ||= do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$content ||= do {
if (open my $fh, "<", $file) {
local $/ = readline $fh;
}
else {
$status = 418;
$reason = "I'm a teapot";
$content_type = "text/plain";
$!;
}
}
MC/DC0%0/2
$content ||= do {
if (open my $fh, "<", $file) {
local $/ = readline $fh;
}
else {
$status = 418;
$reason = "I'm a teapot";
$content_type = "text/plain";
$!;
}
}
$content
do {
if (open my $fh, "<", $file) {
local $/ = readline $fh;
}
else {
$status = 418;
$reason = "I'm a teapot";
$content_type = "text/plain";
$!;
}
}
Truth table33%1/3
A ||= B
A= $contentB= do {
if (open my $fh, "<", $file) {
local $/ = readline $fh;
}
else {
$status = 418;
$reason = "I'm a teapot";
$content_type = "text/plain";
$!;
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | if (open my $fh, '<', $file) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | { local $/ = <$fh> } | |||||||||||||||||||||||||||||||||||||||||
| 127 | else | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | { $status = 418; $reason = "I'm a teapot"; $content_type = 'text/plain'; $! } | |||||||||||||||||||||||||||||||||||||||||
| 129 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | ▶ | $content_type ||= 'text/xml' if $file =~ /\.xml$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$content_type ||= "text/xml"
MC/DC0%0/1
$content_type ||= "text/xml"
$content_type
Truth table0%0/2
A
A= $content_type
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | ▶ | $content_type ||= 'application/xhtml+xml' if $file =~ /\.xht(ml)?$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$content_type ||= "application/xhtml+xml"
MC/DC0%0/1
$content_type ||= "application/xhtml+xml"
$content_type
Truth table0%0/2
A
A= $content_type
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | $content_type ||= 'text/html' if $file =~ /\.html?$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$content_type ||= "text/html"
MC/DC0%0/1
$content_type ||= "text/html"
$content_type
Truth table0%0/2
A
A= $content_type
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | ▶ | $content_type ||= 'application/octet-stream'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$content_type ||= "application/octet-stream"
MC/DC0%0/1
$content_type ||= "application/octet-stream"
$content_type
Truth table50%1/2
A
A= $content_type
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | return +{ | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | success => ($status == 200), | |||||||||||||||||||||||||||||||||||||||||
| 138 | status => $status, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | reason => $reason, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | headers => +{ | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 'content-type' => $content_type, | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 'content-length' => length($content), | ||||||||||||||||||||||||||||||||||||||||||
| 143 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | content => $content, | ||||||||||||||||||||||||||||||||||||||||||
| 145 | decoded_content => $content, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | HTML::HTML5::Parser::UA - simple web user agent class | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | use aliased 'HTML::HTML5::Parser::UA'; | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | my $response = UA->get($url); | ||||||||||||||||||||||||||||||||||||||||||
| 160 | die unless $response->{success}; | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | print $response->{decoded_content}; | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | This is a simple wrapper around HTTP::Tiny and LWP::UserAgent to smooth out | ||||||||||||||||||||||||||||||||||||||||||
| 167 | the API differences between them. It only supports bog standard | ||||||||||||||||||||||||||||||||||||||||||
| 168 | C<< get($url) >> requests. | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | If LWP::UserAgent is already in memory, this module will use that. | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | If LWP::UserAgent is not in memory, then this module will use HTTP::Tiny (or | ||||||||||||||||||||||||||||||||||||||||||
| 173 | direct filesystem access for "file://" URLs). | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | If LWP::UserAgent is not in memory, and you attempt to request a URL that | ||||||||||||||||||||||||||||||||||||||||||
| 176 | HTTP::Tiny cannot handle (e.g. an "ftp://" URL), then this module will load | ||||||||||||||||||||||||||||||||||||||||||
| 177 | LWP::UserAgent and die if it cannot be loaded (e.g. is not installed). | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | HTML::HTML5::Parser::UA is used by the C<parse_file> method of | ||||||||||||||||||||||||||||||||||||||||||
| 180 | HTML::HTML5::Parser. | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | =head2 Class Method | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | =item C<< get($url, $ua) >> | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | Gets the URL and returns a hashref similar to HTTP::Tiny's hashrefs, but | ||||||||||||||||||||||||||||||||||||||||||
| 189 | with an additional C<decoded_content> key, which contains the response | ||||||||||||||||||||||||||||||||||||||||||
| 190 | body, decoded into a Perl character string (not a byte string). | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | If $ua is given (it's optional), then this user agent will be used to | ||||||||||||||||||||||||||||||||||||||||||
| 193 | perform the actual request. Must be undef or an LWP::UserAgent object | ||||||||||||||||||||||||||||||||||||||||||
| 194 | (or a subclass) or an HTTP::Tiny object (or a subclass). | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | =head2 Package Variable | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | =item C<< $HTML::HTML5::Parser::NO_LWP >> | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | If true, avoids using LWP::UserAgent. | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | =head1 MOTIVATION | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | L<LWP::UserAgent> is a good piece of software but it has a dependency on | ||||||||||||||||||||||||||||||||||||||||||
| 211 | L<HTML::Parser>. L<HTML::Parser> is only used to provide one fairly | ||||||||||||||||||||||||||||||||||||||||||
| 212 | esoteric feature, which this package doesn't make use of. (It's the | ||||||||||||||||||||||||||||||||||||||||||
| 213 | C<parse_head> option.) | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | Because of that, I don't especially want HTML::HTML5::Parser to have a | ||||||||||||||||||||||||||||||||||||||||||
| 216 | dependency on LWP::UserAgent. Hence this module. | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | L<HTML::HTML5::Parser>. | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | Toby Inkster, E<lt>tobyink@cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | Copyright (C) 2012 by Toby Inkster | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 231 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | =head1 DISCLAIMER OF WARRANTIES | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED | ||||||||||||||||||||||||||||||||||||||||||
| 236 | WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | ||||||||||||||||||||||||||||||||||||||||||
| 237 | MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||