Dist-Zilla-Role-PluginLoader

 view release on metacpan or  search on metacpan

t/loader-configurable.t  view on Meta::CPAN


use strict;
use warnings;

use Test::More tests => 6;
use Test::DZil qw( simple_ini Builder );
use Dist::Zilla::Util::ConfigDumper qw( dump_plugin );
use Test::Differences;

# ABSTRACT: Test Role::PluginLoader directly
{
  package    #
    Dist::Zilla::Plugin::Injected;
  use Moose;
  with 'Dist::Zilla::Role::Plugin';
  use Dist::Zilla::Util::ConfigDumper qw( dump_plugin config_dumper );

  has payload => ( is => ro => );
  has section => ( is => ro => );

  around dump_config => config_dumper( __PACKAGE__, { attrs => [qw( payload section )] } );

  sub plugin_from_config {
    my ( $class, $name, $arg, $section ) = @_;

    return $class->new(
      {
        %{$arg},
        plugin_name => $name,
        zilla       => $section->sequence->assembler->zilla,
        payload     => $arg,
      }
    );
  }
}
{
  package    #
    Dist::Zilla::Plugin::Example;
  use Moose;
  with 'Dist::Zilla::Role::PluginLoader::Configurable';

}

sub getinj {
  my ($zilla) = @_;
  return grep { $_->isa('Dist::Zilla::Plugin::Injected') } @{ $zilla->plugins };
}

sub mkdist {
  my $tz = Builder->from_config( { dist_root => 'invalid' }, { add_files => {@_} } );
  $tz->chrome->logger->set_debug(1);
  return $tz;
}

subtest 'basic, noargs' => sub {
  my $zilla = mkdist(
    'source/dist.ini' => simple_ini(
      [
        'Example' => {
          dz_plugin => 'Injected'
        }
      ]
    )
  );
  $zilla->build;
  is( scalar getinj($zilla), 1, "One plugin loads another 1" );
  eq_or_diff(
    [ map { dump_plugin($_)->{config} } getinj($zilla) ],



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