Dist-Zilla-Plugin-Prereqs-DarkPAN

 view release on metacpan or  search on metacpan

lib/Dist/Zilla/Plugin/Prereqs/DarkPAN.pm  view on Meta::CPAN

use 5.006;    # our
use strict;
use warnings;

package Dist::Zilla::Plugin::Prereqs::DarkPAN;

our $VERSION = 'v0.3.0';

# ABSTRACT: Depend on things from arbitrary places-not-CPAN

our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY

use Moose qw( with has around );
with 'Dist::Zilla::Role::PrereqSource::External';

use namespace::autoclean;














has prereq_phase => (
  is       => 'ro',
  isa      => 'Str',
  lazy     => 1,
  init_arg => undef,
  default  => 'runtime',
);

has prereq_type => (
  is       => 'ro',
  isa      => 'Str',
  lazy     => 1,
  init_arg => undef,
  default  => 'requires',
);

# For full phase control, use above commented code.

has _deps     => ( is => 'ro', isa => 'HashRef', default => sub { {} }, );
has _raw_deps => ( is => 'ro', isa => 'HashRef', default => sub { {} }, );

around 'dump_config' => sub {
  my ( $orig, $self, @args ) = @_;
  my $config = $self->$orig(@args);
  my $localconf = $config->{ +__PACKAGE__ } = {};

  $localconf->{prereq_phase} = $self->prereq_phase;
  $localconf->{prereq_type}  = $self->prereq_type;
  $localconf->{_raw_deps}    = $self->_raw_deps;

  $localconf->{ q[$] . __PACKAGE__ . q[::VERSION] } = $VERSION
    unless __PACKAGE__ eq ref $self;
  return $config;
};

__PACKAGE__->meta->make_immutable;
no Moose;

sub _add_dep {
  my ( undef, $stash, $args ) = @_;
  $stash->{deps} = {} unless exists $stash->{deps};
  my $ds     = $stash->{deps};
  my $logger = $stash->{logger};

  my $key   = $args->{key};
  my $value = $args->{value};

  # TODO perhaps have support for multiple URLs with either some
  # fallback strategy or round-robbin or random-source support.
  # Not a priority atm.
  return $logger->log_fatal( [ 'tried to define base uri for \'%s\' more than once.', $key ] )
    if exists $ds->{$key};

  return ( $ds->{$key} = $value );

}

sub _add_attribute {
  my ( undef, $stash, $args ) = @_;

  $stash->{attributes} = {} unless exists $stash->{attributes};

  my $attributes = $stash->{attributes};
  my $logger     = $stash->{logger};

  my $key       = $args->{key};
  my $attribute = $args->{attribute};
  my $value     = $args->{value};

  my $supported_attrs = { map { $_ => 1 } qw( minversion uri ) };

  return $logger->log_fatal( [ 'Attribute \'%s\' for key \'%s\' not supported.', $attribute, $key, ], )
    if not exists $supported_attrs->{$attribute};

  $attributes->{$key} = {} unless exists $attributes->{$key};

  return $logger->log_fatal( [ 'tried to set attribute \'%s\' for %s more than once.', $attribute, $key, ] )
    if exists $attributes->{$key}->{$attribute};

  return ( $attributes->{$key}->{$attribute} = $value );



( run in 1.466 second using v1.01-cache-2.11-cpan-9581c071862 )