File Coverage

blib/lib/Dist/Zilla/Role/Plugin.pm
Criterion Covered Total %
statement 25 25 100.0
branch n/a
condition 2 2 100.0
subroutine 9 9 100.0
pod 0 4 0.0
total 36 40 90.0


line stmt bran cond sub pod time code
1             package Dist::Zilla::Role::Plugin 6.037;
2             # ABSTRACT: something that gets plugged in to Dist::Zilla
3              
4 52     52   3601 use Moose::Role;
  52         153  
  52         656  
5             with 'Dist::Zilla::Role::ConfigDumper';
6              
7 52     52   315491 use Dist::Zilla::Pragmas;
  52         128  
  52         551  
8              
9 52     52   406 use Params::Util qw(_HASHLIKE);
  52         204  
  52         4954  
10 52     52   411 use Moose::Util::TypeConstraints 'class_type';
  52         134  
  52         617  
11              
12 52     52   27864 use namespace::autoclean;
  52         121  
  52         572  
13              
14             #pod =head1 DESCRIPTION
15             #pod
16             #pod The Plugin role should be applied to all plugin classes. It provides a few key
17             #pod methods and attributes that all plugins will need.
18             #pod
19             #pod =attr plugin_name
20             #pod
21             #pod The plugin name is generally determined when configuration is read.
22             #pod
23             #pod =cut
24              
25             has plugin_name => (
26             is => 'ro',
27             isa => 'Str',
28             required => 1,
29             );
30              
31             #pod =attr zilla
32             #pod
33             #pod This attribute contains the Dist::Zilla object into which the plugin was
34             #pod plugged.
35             #pod
36             #pod =cut
37              
38             has zilla => (
39             is => 'ro',
40             isa => class_type('Dist::Zilla'),
41             required => 1,
42             weak_ref => 1,
43             );
44              
45             #pod =method log
46             #pod
47             #pod The plugin's C<log> method delegates to the Dist::Zilla object's
48             #pod L<Dist::Zilla/log> method after including a bit of argument-munging.
49             #pod
50             #pod =cut
51              
52             has logger => (
53             is => 'ro',
54             lazy => 1,
55             handles => [ qw(log log_debug log_fatal) ],
56             default => sub {
57             $_[0]->zilla->chrome->logger->proxy({
58             proxy_prefix => '[' . $_[0]->plugin_name . '] ',
59             });
60             },
61             );
62              
63             # We define these effectively-pointless subs here to allow other roles to
64             # modify them with around. -- rjbs, 2010-03-21
65       480 0   sub mvp_multivalue_args {};
66 506     506 0 88079 sub mvp_aliases { return {} };
67              
68             sub plugin_from_config {
69 753     753 0 2104 my ($class, $name, $arg, $section) = @_;
70              
71 753         3130 my $self = $class->new({
72             %$arg,
73             plugin_name => $name,
74             zilla => $section->sequence->assembler->zilla,
75             });
76             }
77              
78             sub register_component {
79 753     753 0 2695 my ($class, $name, $arg, $section) = @_;
80              
81 753         3003 my $self = $class->plugin_from_config($name, $arg, $section);
82              
83 752   100     15867 my $version = $self->VERSION || 0;
84              
85 752         4432 $self->log_debug([ 'online, %s v%s', $self->meta->name, $version ]);
86              
87 752         36884 push @{ $self->zilla->plugins }, $self;
  752         27449  
88              
89 752         2969 return;
90             }
91              
92             1;
93              
94             __END__
95              
96             =pod
97              
98             =encoding UTF-8
99              
100             =head1 NAME
101              
102             Dist::Zilla::Role::Plugin - something that gets plugged in to Dist::Zilla
103              
104             =head1 VERSION
105              
106             version 6.037
107              
108             =head1 DESCRIPTION
109              
110             The Plugin role should be applied to all plugin classes. It provides a few key
111             methods and attributes that all plugins will need.
112              
113             =head1 PERL VERSION
114              
115             This module should work on any version of perl still receiving updates from
116             the Perl 5 Porters. This means it should work on any version of perl
117             released in the last two to three years. (That is, if the most recently
118             released version is v5.40, then this module should work on both v5.40 and
119             v5.38.)
120              
121             Although it may work on older versions of perl, no guarantee is made that the
122             minimum required version will not be increased. The version may be increased
123             for any reason, and there is no promise that patches will be accepted to
124             lower the minimum required perl.
125              
126             =head1 ATTRIBUTES
127              
128             =head2 plugin_name
129              
130             The plugin name is generally determined when configuration is read.
131              
132             =head2 zilla
133              
134             This attribute contains the Dist::Zilla object into which the plugin was
135             plugged.
136              
137             =head1 METHODS
138              
139             =head2 log
140              
141             The plugin's C<log> method delegates to the Dist::Zilla object's
142             L<Dist::Zilla/log> method after including a bit of argument-munging.
143              
144             =head1 AUTHOR
145              
146             Ricardo SIGNES 😏 <cpan@semiotic.systems>
147              
148             =head1 COPYRIGHT AND LICENSE
149              
150             This software is copyright (c) 2026 by Ricardo SIGNES.
151              
152             This is free software; you can redistribute it and/or modify it under
153             the same terms as the Perl 5 programming language system itself.
154              
155             =cut