File Coverage

lib/Dist/Zilla/Util/RoleDB/Entry.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1 1     1   722 use 5.008; # utf8
  1         2  
  1         33  
2 1     1   4 use strict;
  1         1  
  1         30  
3 1     1   3 use warnings;
  1         1  
  1         24  
4 1     1   533 use utf8;
  1         7  
  1         5  
5              
6             package Dist::Zilla::Util::RoleDB::Entry;
7              
8             our $VERSION = '0.003001';
9              
10             # ABSTRACT: Extracted meta-data about a role
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14 1     1   219 use Moose qw( has );
  0            
  0            
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26              
27              
28              
29              
30             has name => (
31             isa => Str =>,
32             is => ro =>,
33             required => 1,
34             documentation => q[The unprefixed version of the role name, ie: -Foo => DZR::Foo],
35             );
36              
37              
38              
39              
40              
41              
42              
43              
44              
45             has full_name => (
46             isa => Str =>,
47             is => ro =>,
48             lazy_build => 1,
49             documentation => q[The fully qualified version of the role name],
50             );
51              
52             sub _build_full_name {
53             my ($self) = @_;
54             my $role_name = $self->name;
55             return $role_name unless $role_name =~ /\A-/msx;
56             $role_name =~ s{\A-}{Dist::Zilla::Role::}msx;
57             return $role_name;
58             }
59              
60              
61              
62              
63              
64              
65              
66              
67              
68              
69              
70              
71              
72              
73              
74              
75              
76              
77              
78              
79              
80              
81              
82              
83              
84              
85              
86              
87              
88              
89              
90              
91              
92              
93              
94             has required_modules => (
95             isa => 'ArrayRef[Str]' =>,
96             is => ro =>,
97             lazy_build => 1,
98             ## no critic (ProhibitImplicitNewlines)
99             documentation => <<'EOF', );
100             A list of things that must be manually require()d for the module to exist.
101             Note: This should not be needed for anything, as its really only intended
102             as a way to make hidden packages require()able.
103             Usually, this will be exactly one item, and it will be the same as the modules name.
104             EOF
105              
106             sub _build_required_modules {
107             my ($self) = @_;
108             return [ $self->full_name ];
109             }
110              
111              
112              
113              
114              
115              
116              
117             sub is_phase { return }
118              
119              
120              
121              
122              
123              
124              
125              
126              
127             has description => (
128             isa => Str =>,
129             is => ro =>,
130             required => 1,
131             documentation => q[A text description of the role. A copy of ABSTRACT would be fine],
132             );
133              
134              
135              
136              
137              
138              
139              
140             has deprecated => (
141             isa => Bool =>,
142             is => ro =>,
143             lazy_build => 1,
144             documentation => q[Set this to 1 if this role is deprecated],
145             );
146              
147             sub _build_deprecated { return }
148              
149             no Moose;
150             __PACKAGE__->meta->make_immutable;
151              
152              
153              
154              
155              
156              
157              
158              
159              
160              
161             sub require_module {
162             my ($self) = @_;
163             require Module::Runtime;
164             for my $module ( @{ $self->required_modules } ) {
165             Module::Runtime::require_module($module);
166             }
167             return $self->full_name;
168             }
169              
170             1;
171              
172             __END__
173              
174             =pod
175              
176             =encoding UTF-8
177              
178             =head1 NAME
179              
180             Dist::Zilla::Util::RoleDB::Entry - Extracted meta-data about a role
181              
182             =head1 VERSION
183              
184             version 0.003001
185              
186             =head1 SYNOPSIS
187              
188             use Dist::Zilla::Util::RoleDB::Entry;
189             my $entry = Dist::Zilla::Util::RoleDB::Entry->new(
190             name => "-FileGatherer",
191             description => "A thing that adds files to your dist"
192             );
193              
194             =head1 METHODS
195              
196             =head2 is_phase
197              
198             Returns false
199              
200             =head2 C<require_module>
201              
202             Load the module itself.
203              
204             Usually, this just amounts to requiring C<full_name>, but it might not be
205             in the case somebody has manually modified C<required_modules>
206              
207             =head1 ATTRIBUTES
208              
209             =head2 C<name>
210              
211             Contains the short name for the role, in a form acceptable by C<Dist::Zilla>'s C<plugins_with> method.
212              
213             e.g:
214              
215             -FileGatherer
216              
217             Because
218              
219             zilla->plugins_with(-FileGatherer)
220              
221             =head2 C<full_name>
222              
223             Contains the fully qualified version of the role.
224              
225             For instance, when C<name> is C<-FileGatherer>, C<full_name> will be C<Dist::Zilla::Role::FileGatherer>
226              
227             =head2 C<required_modules>
228              
229             This contains an C<ArrayRef> of Modules that are required if one ever intends to use the module in C<full_name>.
230              
231             Note, that this is not intended to be really used. It only exists as a helper in the event one wishes to document
232             a roles existence in a file other than one matching its name.
233              
234             For example:
235              
236             Foo.pm:
237              
238             package Foo;
239              
240             use Moose::Role;
241              
242             package Bar;
243              
244             use Moose::Role;
245              
246             In such a scenario, one cannot get Bar without C<require Foo>
247              
248             So here,
249              
250             ->new( name => 'Foo' ); # required_modules is automatically [Foo]
251             ->new( name => 'Bar', required_modules => ['Foo'] );
252              
253             Also, if a role has peculiar load order requirements ( like seen in Class::MOP ) that means
254             certain other libraries must be C<require>'d before C<require>ing the module itself, this would be a convenient place to put such information.
255              
256             This mechanism is mostly to support C<< $entry->require_module >>
257              
258             =head2 C<description>
259              
260             Contains a textual description of the Role.
261              
262             Usually, a copy of the Roles "ABSTRACT" will do the trick.
263              
264             =head2 C<deprecated>
265              
266             If a role is deprecated, setting this may be useful.
267              
268             =head1 AUTHOR
269              
270             Kent Fredric <kentnl@cpan.org>
271              
272             =head1 COPYRIGHT AND LICENSE
273              
274             This software is copyright (c) 2015 by Kent Fredric <kentfredric@gmail.com>.
275              
276             This is free software; you can redistribute it and/or modify it under
277             the same terms as the Perl 5 programming language system itself.
278              
279             =cut