File Coverage

blib/lib/Dist/Zilla/Util/RoleDB/Entry.pm
Criterion Covered Total %
statement 24 33 72.7
branch 1 2 50.0
condition n/a
subroutine 8 11 72.7
pod 2 2 100.0
total 35 48 72.9


line stmt bran cond sub pod time code
1 4     4   1736 use 5.006;
  4         9  
  4         110  
2 4     4   13 use strict;
  4         4  
  4         85  
3 4     4   12 use warnings;
  4         3  
  4         183  
4              
5             package Dist::Zilla::Util::RoleDB::Entry;
6              
7             our $VERSION = '0.004000'; # TRIAL
8              
9             # ABSTRACT: Extracted meta-data about a role
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 4     4   481 use Moo qw( has );
  4         10384  
  4         18  
14 4     4   1655 use Carp qw( croak );
  4         4  
  4         1790  
15              
16             ## no critic (NamingConventions)
17             my $is_Str = sub { 'SCALAR' eq ref \$_[0] or 'SCALAR' eq ref \( my $val = $_[0] ) };
18             my $is_ArrayRef = sub {
19             return 'ARRAY' eq ref $_[0] unless $_[1];
20             return unless 'ARRAY' eq ref $_[0];
21             for ( @{ $_[0] } ) {
22             return unless $_[1]->($_);
23             }
24             1;
25             };
26             my $is_Bool = sub { not defined $_[0] or q() eq $_[0] or '0' eq $_[0] or '1' eq $_[0] };
27              
28              
29              
30              
31              
32              
33              
34              
35              
36              
37              
38              
39              
40              
41              
42             has name => (
43             isa => sub { $is_Str->( $_[0] ) or croak 'name must be a Str' },
44             is => ro =>,
45             required => 1,
46             documentation => q[The unprefixed version of the role name, ie: -Foo => DZR::Foo],
47             );
48              
49              
50              
51              
52              
53              
54              
55              
56              
57             has full_name => (
58             isa => sub { $is_Str->( $_[0] ) or croak 'full_name must be a Str' },
59             is => ro =>,
60             lazy => 1,
61             builder => '_build_full_name',
62             documentation => q[The fully qualified version of the role name],
63             );
64              
65             sub _build_full_name {
66 54     54   71119 my ($self) = @_;
67 54         76 my $role_name = $self->name;
68 54 50       141 return $role_name unless $role_name =~ /\A-/msx;
69 54         111 $role_name =~ s{\A-}{Dist::Zilla::Role::}msx;
70 54         774 return $role_name;
71             }
72              
73              
74              
75              
76              
77              
78              
79              
80              
81              
82              
83              
84              
85              
86              
87              
88              
89              
90              
91              
92              
93              
94              
95              
96              
97              
98              
99              
100              
101              
102              
103              
104              
105              
106              
107             has required_modules => (
108             isa => sub { $is_ArrayRef->( $_[0], $is_Str ) or croak 'required_modules must be an ArrayRef of Str' },
109             is => ro =>,
110             lazy => 1,
111             builder => '_build_required_modules',
112             ## no critic (ProhibitImplicitNewlines)
113             documentation => <<'EOF', );
114             A list of things that must be manually require()d for the module to exist.
115             Note: This should not be needed for anything, as its really only intended
116             as a way to make hidden packages require()able.
117             Usually, this will be exactly one item, and it will be the same as the modules name.
118             EOF
119              
120             sub _build_required_modules {
121 0     0   0 my ($self) = @_;
122 0         0 return [ $self->full_name ];
123             }
124              
125              
126              
127              
128              
129              
130              
131 30     30 1 34 sub is_phase { return }
132              
133              
134              
135              
136              
137              
138              
139              
140              
141             has description => (
142             isa => sub { $is_Str->( $_[0] ) or croak 'description must be a Str' },
143             is => ro =>,
144             required => 1,
145             documentation => q[A text description of the role. A copy of ABSTRACT would be fine],
146             );
147              
148              
149              
150              
151              
152              
153              
154             has deprecated => (
155             isa => sub { $is_Bool->( $_[0] ) or croak 'deprecated must be Boolean' },
156             is => ro =>,
157             lazy => 1,
158             builder => '_build_deprecated',
159             documentation => q[Set this to 1 if this role is deprecated],
160             );
161              
162 0     0     sub _build_deprecated { return }
163              
164 4     4   20 no Moo;
  4         4  
  4         14  
165              
166              
167              
168              
169              
170              
171              
172              
173              
174              
175             sub require_module {
176 0     0 1   my ($self) = @_;
177 0           require Module::Runtime;
178 0           for my $module ( @{ $self->required_modules } ) {
  0            
179 0           Module::Runtime::require_module($module);
180             }
181 0           return $self->full_name;
182             }
183              
184             1;
185              
186             __END__