First try with HTTP::Tiny, fallback on `wget`
authorMax Maischein <corion@corion.net>
Tue, 21 May 2013 17:11:22 +0000 (19:11 +0200)
committerMax Maischein <corion@corion.net>
Sun, 6 Oct 2013 17:48:07 +0000 (19:48 +0200)
This tries downloads first with the built-in HTTP::Tiny
before it falls back to the external `wget` tool. Arguably,
the reliance on `wget` could be eliminated to reduce the
amount of code clutter.

Porting/sync-with-cpan

index c3f9ce1..dee39ee 100755 (executable)
@@ -199,7 +199,12 @@ unless ($tarball) {
     # Poor man's cache
     #
     unless (-f $package_file && -M $package_file < 1) {
-        system wget => $package_url, '-qO', $package_file;
+        eval {
+            require HTTP::Tiny;
+            my $http= HTTP::Tiny->new();
+            $http->mirror( $package_url => $package_file );
+            1
+        } or system wget => $package_url, '-qO', $package_file;
     }
 
     my  $new_line = `grep '^$cpan_mod ' $package_file`
@@ -217,7 +222,12 @@ unless ($tarball) {
     #
     # Fetch the new distro
     #
-    system wget => $url, '-qO', $new_file;
+    eval {
+        require HTTP::Tiny;
+        my $http= HTTP::Tiny->new();
+        $http->mirror( $url => $new_file );
+        1
+    } or system wget => $url, '-qO', $new_file;
 }
 else {
     $new_file     = $tarball;