Replace LWP with HTTP::Tiny
authorMarius Gavrilescu <marius@ieval.ro>
Sun, 12 Jul 2015 10:30:24 +0000 (13:30 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sun, 12 Jul 2015 10:30:24 +0000 (13:30 +0300)
Makefile.PL
lib/WWW/Offliberty.pm

index a123b4058170c9468a514297f503c867ad13931f..191da8e8030b83f7427f44635a335ceb7c671084 100644 (file)
@@ -16,7 +16,7 @@ WriteMakefile(
        PREREQ_PM        => {
                qw/Getopt::Long      0
                   HTML::TreeBuilder 0
-                  LWP::UserAgent    0/
+                  HTTP::Tiny        0/
                 },
        META_ADD         => {
                dynamic_config => 0,
index 3f9a152b8e8d7a305cb0283ad5a6617b27d4e5e5..a8ca5769313c192d729bfa7400d59dd89d7146eb 100644 (file)
@@ -7,15 +7,18 @@ use parent qw/Exporter/;
 our $VERSION = '0.002';
 our @EXPORT_OK = qw/off/;
 
+use constant OFF_URL => 'http://offliberty.com/off54.php';
+
 use HTML::TreeBuilder;
-use LWP::UserAgent;
+use HTTP::Tiny;
 
-my $ua = LWP::UserAgent->new;
+my $http = HTTP::Tiny->new(agent => "WWW-Offliberty/$VERSION ");
 
 sub off{
        my ($url, @params) = @_;
-       my $content = $ua->post("http://offliberty.com/off54.php", {track => $url, @params})->decoded_content;
-       my $root = HTML::TreeBuilder->new_from_content($content);
+       my $ret = $http->post_form(OFF_URL, {track => $url, @params});
+       die $ret->{reason} unless $ret->{success};
+       my $root = HTML::TreeBuilder->new_from_content($ret->{content});
        map { $_->attr('href') } $root->look_down(qw/_tag a class download/);
 }
 
This page took 0.012335 seconds and 4 git commands to generate.