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