App-cpangitify

 view release on metacpan or  search on metacpan

lib/App/cpangitify.pm  view on Meta::CPAN

package App::cpangitify;

use strict;
use warnings;
use autodie qw( :system );
use 5.020;
use experimental qw( signatures );
use Getopt::Long qw( GetOptions );
use Pod::Usage qw( pod2usage );
use Path::Class qw( file dir );
use Git::Wrapper;
use File::Temp qw( tempdir );
use File::chdir;
use JSON::PP qw( decode_json );
use URI;
use PerlX::Maybe qw( maybe );
use File::Copy::Recursive qw( rcopy );
use File::Basename qw( basename );
use Archive::Libarchive::Extract;
use CPAN::ReleaseHistory;
use HTTP::Tiny;

# ABSTRACT: Convert cpan distribution from BackPAN to a git repository
our $VERSION = '0.21'; # VERSION


our $ua  = HTTP::Tiny->new( verify_SSL => 1 );
our $opt_metacpan_url;

sub _rm_rf ($file)
{
  if($file->is_dir && ! -l $file)
  {
    _rm_rf($_) for $file->children;
  }

  $file->remove || die "unable to delete $file";
}

our $_run_cb = sub {};
our $original_run = \&Git::Wrapper::RUN;
our $trace = 0;

sub _run_wrapper ($self, @command)
{
  my @display;
  foreach my $arg (@command)
  {
    if(ref($arg) eq 'HASH')
    {
      foreach my $k (keys %$arg)
      {
        my $v = $arg->{$k};
        push @display, "--$k";
        push @display, $v =~ /\s/ ? "'$v'" : $v
          if $v ne '1'; # yes there is a weird exception for this :P
      }
    }
    else
    {
      push @display, $arg;
    }
  }
  $_run_cb->($self, @display);
  say "+ git @display" if $trace;
  $original_run->($self, @command);
}

sub author ($cpanid)
{
  state $cache = {};

  unless(defined $cache->{$cpanid})
  {
    my $uri = URI->new($opt_metacpan_url . "v1/author/" . $cpanid);
    my $res = $ua->get($uri);
    unless($res->{success})
    {
      say "error fetching $uri";
      say $res->{reason};
      return 2;
    }
    $cache->{$cpanid} = decode_json($res->{content})
  }

  my $email = $cache->{$cpanid}->{email};
  $email = $email->[0] if ref($email) eq 'ARRAY';



( run in 2.736 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )