Dist::Zilla::Role::Plugin - something that gets plugged in to Dist::Zilla


Dist-Zilla documentation Contained in the Dist-Zilla distribution.

Index


Code Index:

NAME

Top

Dist::Zilla::Role::Plugin - something that gets plugged in to Dist::Zilla

VERSION

Top

version 4.200008

DESCRIPTION

Top

The Plugin role should be applied to all plugin classes. It provides a few key methods and attributes that all plugins will need.

ATTRIBUTES

Top

plugin_name

The plugin name is generally determined when configuration is read.

zilla

This attribute contains the Dist::Zilla object into which the plugin was plugged.

METHODS

Top

log

The plugin's log method delegates to the Dist::Zilla object's log in Dist::Zilla method after including a bit of argument-munging.

AUTHOR

Top

Ricardo SIGNES <rjbs@cpan.org>

COPYRIGHT AND LICENSE

Top


Dist-Zilla documentation Contained in the Dist-Zilla distribution.

package Dist::Zilla::Role::Plugin;
BEGIN {
  $Dist::Zilla::Role::Plugin::VERSION = '4.200008';
}
# ABSTRACT: something that gets plugged in to Dist::Zilla
use Moose::Role;
with 'Dist::Zilla::Role::ConfigDumper';

use Params::Util qw(_HASHLIKE);
use Moose::Autobox;
use MooseX::Types;

use namespace::autoclean;


has plugin_name => (
  is  => 'ro',
  isa => 'Str',
  required => 1,
);


has zilla => (
  is  => 'ro',
  isa => class_type('Dist::Zilla'),
  required => 1,
  weak_ref => 1,
);


has logger => (
  is   => 'ro',
  lazy => 1,
  handles => [ qw(log log_debug log_fatal) ],
  default => sub {
    $_[0]->zilla->chrome->logger->proxy({
      proxy_prefix => '[' . $_[0]->plugin_name . '] ',
    });
  },
);

# We define these effectively-pointless subs here to allow other roles to
# modify them with around. -- rjbs, 2010-03-21
sub mvp_multivalue_args {};
sub mvp_aliases         { return {} };

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

  my $self = $class->new(
    $arg->merge({
      plugin_name => $name,
      zilla       => $section->sequence->assembler->zilla,
    }),
  );
}

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

  my $self = $class->plugin_from_config($name, $arg, $section);

  my $version = $self->VERSION || 0;

  $self->log_debug([ 'online, %s v%s', $self->meta->name, $version ]);

  $self->zilla->plugins->push($self);

  return;
}

no Moose::Role;
1;

__END__