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.029;
2             # ABSTRACT: something that gets plugged in to Dist::Zilla
3              
4 52     52   3265 use Moose::Role;
  52         118  
  52         605  
5             with 'Dist::Zilla::Role::ConfigDumper';
6              
7 52     52   296754 use Dist::Zilla::Pragmas;
  52         136  
  52         555  
8              
9 52     52   442 use Params::Util qw(_HASHLIKE);
  52         167  
  52         4281  
10 52     52   514 use Moose::Util::TypeConstraints 'class_type';
  52         153  
  52         656  
11              
12 52     52   24956 use namespace::autoclean;
  52         166  
  52         576  
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 83510 sub mvp_aliases { return {} };
67              
68             sub plugin_from_config {
69 753     753 0 2051 my ($class, $name, $arg, $section) = @_;
70              
71 753         3021 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 2654 my ($class, $name, $arg, $section) = @_;
80              
81 753         2939 my $self = $class->plugin_from_config($name, $arg, $section);
82              
83 752   100     14260 my $version = $self->VERSION || 0;
84              
85 752         4407 $self->log_debug([ 'online, %s v%s', $self->meta->name, $version ]);
86              
87 752         26466 push @{ $self->zilla->plugins }, $self;
  752         21783  
88              
89 752         2397 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.029
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 released
117             in the last two to three years. (That is, if the most recently released
118             version is v5.40, then this module should work on both v5.40 and v5.38.)
119              
120             Although it may work on older versions of perl, no guarantee is made that the
121             minimum required version will not be increased. The version may be increased
122             for any reason, and there is no promise that patches will be accepted to lower
123             the minimum required perl.
124              
125             =head1 ATTRIBUTES
126              
127             =head2 plugin_name
128              
129             The plugin name is generally determined when configuration is read.
130              
131             =head2 zilla
132              
133             This attribute contains the Dist::Zilla object into which the plugin was
134             plugged.
135              
136             =head1 METHODS
137              
138             =head2 log
139              
140             The plugin's C<log> method delegates to the Dist::Zilla object's
141             L<Dist::Zilla/log> method after including a bit of argument-munging.
142              
143             =head1 AUTHOR
144              
145             Ricardo SIGNES 😏 <cpan@semiotic.systems>
146              
147             =head1 COPYRIGHT AND LICENSE
148              
149             This software is copyright (c) 2022 by Ricardo SIGNES.
150              
151             This is free software; you can redistribute it and/or modify it under
152             the same terms as the Perl 5 programming language system itself.
153              
154             =cut