Alien-Build-Plugin-Fetch-Cache

 view release on metacpan or  search on metacpan

bin/abcache  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use warnings;
use autodie;
use 5.010001;
use Path::Tiny qw( path );
use Pod::Usage qw( pod2usage );
use Getopt::Long qw( GetOptions );
use Sereal 3.015 qw( decode_sereal );
use File::Glob qw( bsd_glob );
use URI;
use Number::Bytes::Human qw( format_bytes );

# ABSTRACT: Command line interface to Alien::Build::Plugin::Fetch::Cache
# PODNAME: abcache
our $VERSION = '0.05'; # VERSION


my $opt_list;
my $opt_clear;

GetOptions(
  'list'      => \$opt_list,
  'clear'     => \$opt_clear,
  'version|v' => sub { say "abcache (Alien::Build::Plugin::Fetch::Cache) version @{[ $main::VERSION // 'dev' ]}" },
  'help|h'    => sub { pod2usage( -exitval => 0 ) },
) || pod2usage( -exitval => 2 );

my $root = path(bsd_glob '~/.alienbuild/plugin_fetch_cache');

sub recurse
{
  my $cb = shift;
  my $dir = shift // $root;
  my $list = shift // [];

  foreach my $child (sort $dir->children)
  {
    next unless -d $child;

lib/Alien/Build/Plugin/Fetch/Cache.pm  view on Meta::CPAN

package Alien::Build::Plugin::Fetch::Cache;

use strict;
use warnings;
use 5.010001;
use Alien::Build::Plugin;
use URI 1.71;
use Path::Tiny 0.100 ();
use Sereal 3.015 qw( encode_sereal decode_sereal );
use Digest::MD5;
use File::Glob qw( bsd_glob );

# ABSTRACT: Alien::Build plugin to cache files downloaded from the internet
our $VERSION = '0.05'; # VERSION


sub _local_file
{
  my($uri) = @_;

  Path::Tiny
    ->new(bsd_glob '~/.alienbuild/plugin_fetch_cache')
    ->child($uri->scheme)
    ->child($uri->host)
    ->child($uri->path)
    ->child('meta');
}

sub init
{
  my($self, $meta) = @_;

lib/Alien/Build/Plugin/Fetch/Cache.pm  view on Meta::CPAN

          {
            $md5->add($res->{content});
          }
          else
          {
            open my $fh, '<', $res->{path};
            $md5->addfile($fh);
            close $fh;
          }

          my $data = Path::Tiny->new(bsd_glob '~/.alienbuild/plugin_fetch_cache/payload')
                     ->child($md5->hexdigest)
                     ->child($res->{filename});
          $data->parent->mkpath;

          my $res2 = {
            type     => 'file',
            filename => $res->{filename},
            path     => $data->stringify,
            protocol => $res->{protocol},
          };



( run in 0.646 second using v1.01-cache-2.11-cpan-49f99fa48dc )