Alien-Build-Plugin-Fetch-Prompt

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

{
   "abstract" : "Alien::Build plugin to prompt a user before making external download",
   "author" : [
      "Graham Ollis <plicease@cpan.org>"
   ],
   "dynamic_config" : 0,
   "generated_by" : "Dist::Zilla version 6.025, CPAN::Meta::Converter version 2.150010",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",

META.yml  view on Meta::CPAN

---
abstract: 'Alien::Build plugin to prompt a user before making external download'
author:
  - 'Graham Ollis <plicease@cpan.org>'
build_requires:
  Capture::Tiny: '0'
  ExtUtils::MakeMaker: '0'
  Test2::Mock: '0.000121'
  Test2::Tools::Process: '0'
  Test2::V0: '0.000121'
  Test::Alien::Build: '0'
  perl: '5.010'

Makefile.PL  view on Meta::CPAN

    exit;
  }
}
# This file was automatically generated by Dist::Zilla::Plugin::Author::Plicease::MakeMaker v2.71.
use strict;
use warnings;
use 5.010;
use ExtUtils::MakeMaker;

my %WriteMakefileArgs = (
  "ABSTRACT"           => "Alien::Build plugin to prompt a user before making external download",
  "AUTHOR"             => "Graham Ollis <plicease\@cpan.org>",
  "CONFIGURE_REQUIRES" => {
    "ExtUtils::MakeMaker" => 0
  },
  "DISTNAME"         => "Alien-Build-Plugin-Fetch-Prompt",
  "LICENSE"          => "perl",
  "MIN_PERL_VERSION" => "5.010",
  "NAME"             => "Alien::Build::Plugin::Fetch::Prompt",
  "PM"               => {
    "lib/Alien/Build/Plugin/Fetch/Prompt.pm"               => "\$(INST_LIB)/Alien/Build/Plugin/Fetch/Prompt.pm",

README  view on Meta::CPAN

NAME

    Alien::Build::Plugin::Fetch::Prompt - Alien::Build plugin to prompt a
    user before making external download

VERSION

    version 0.61

SYNOPSIS

    In your ~/.alienbuild/rc.pl

     preload 'Fetch::Prompt';
     1;

DESCRIPTION

    This plugin allows you to force Alien::Build to prompt the user and ask
    for permission before downloading anything from the internet. It uses
    the ExtUtils::MakeMaker prompt function, so that it will do the
    sensible thing, like not infinitely halt install on non-interactive
    installs. The default response is yes, which is usually reasonable (and
    the default if you do not use this plugin at all), but you may change
    this by using the ALIEN_DOWNLOAD environment variable (see below).

ENVIRONMENT

 ALIEN_DOWNLOAD

    Set this environment variable to the default response. Should be either

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

package Alien::Build::Plugin::Fetch::Prompt;

use strict;
use warnings;
use 5.010;
use Alien::Build::Plugin;

# ABSTRACT: Alien::Build plugin to prompt a user before making external download
our $VERSION = '0.61'; # VERSION


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

  $meta->add_requires('share' => 'ExtUtils::MakeMaker' => 0 );

  $meta->before_hook(
    fetch => sub {
      my($build, $url) = @_;
      $url ||= $build->meta_prop->{start_url} || $build->meta_prop->{plugin_download_negotiate_default_url};
      my $value = ExtUtils::MakeMaker::prompt("Downloading $url, is that okay?", $ENV{ALIEN_DOWNLOAD} || 'yes');
      unless($value =~ /^(y|yes)$/i)
      {
        $build->log("User refussed to download $url");
        # Do a hard exit.  If the user insists, there isn't a way to recover really.
        exit 2;
      }
    }
  );
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Alien::Build::Plugin::Fetch::Prompt - Alien::Build plugin to prompt a user before making external download

=head1 VERSION

version 0.61

=head1 SYNOPSIS

In your ~/.alienbuild/rc.pl

 preload 'Fetch::Prompt';
 1;

=head1 DESCRIPTION

This plugin allows you to force L<Alien::Build> to prompt the user and ask for permission
before downloading anything from the internet.  It uses the L<ExtUtils::MakeMaker> C<prompt>
function, so that it will do the sensible thing, like not infinitely halt install on
non-interactive installs.  The default response is C<yes>, which is usually reasonable
(and the default if you do not use this plugin at all), but you may change this by using
the C<ALIEN_DOWNLOAD> environment variable (see below).

=head1 ENVIRONMENT

=head2 ALIEN_DOWNLOAD

Set this environment variable to the default response.  Should be either C<yes> or C<no>.

t/alien_build_plugin_fetch_promp.t  view on Meta::CPAN

};

my $mock = Test2::Mock->new(
  class => 'ExtUtils::MakeMaker',
);

subtest 'user says yes' => sub {

  my($msg, $def);

  $mock->override(prompt => sub ($;$) { ($msg,$def) = @_; return 'y' });

  subtest 'default url' => sub {
  
    is intercept_exit {
      $build->fetch;
    }, U();
    
    like $msg, qr{https://alienfile.org/foo/bar/baz};
    note "msg = $msg";
    

t/alien_build_plugin_fetch_promp.t  view on Meta::CPAN

    }, U();
    
    is $def, 'no';
  
  };

};

subtest 'user says no' => sub {

  $mock->override(prompt => sub ($;$) { 'n' });
  
  is intercept_exit { capture_merged { $build->fetch } }, 2;

};

done_testing;



( run in 0.739 second using v1.01-cache-2.11-cpan-0b5f733616e )