blib/lib/Venus/Meta.pm

filter: Statementstmt 96.1% 251 / 261 Branchbran 78.4% 80 / 102 Conditioncond 75.0% 18 / 24 MC/DCmcdc 57.1% 8 / 14 Subroutinesub 100% 41 / 41 Podpod 75.0% 18 / 24 totaltotal 89.2% 416 / 466 CC 74 SCAR 16.4
CC
74
Cov
90%
search
12.0
masks
8.4
mixins
7.3
CRAP 5.2
« blib/lib/Venus/Role/Optional.pm ↑ Summary blib/lib/Venus/Task.pm »
1 package Venus::Meta;
2  
3 120 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 120 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 120 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 120 ▶use Venus;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # INHERITS
13  
14 120 ▶use base 'Venus::Core';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # METHODS
17  
18 3 ▶sub attr {
Subroutine attr: called CC=3 SCAR=11.0
Pod documented
19 3 my ($self, $name) = @_;
20  
21 3 ▶ return 0 if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 3 3
22  
23 3 my $data = {map +($_,$_), @{$self->attrs}};
24  
25 3 ▶ return $data->{$name} ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$data->{$name} ? : 2 1 3
26 }
27  
28 921 ▶sub attrs {
Subroutine attrs: called CC=7 SCAR=19.5
Pod documented
29 921 my ($self) = @_;
30  
31 921 ▶ if ($self->{attrs}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"attrs"}) 779 142 921
32 779 ▶ return wantarray ? (@{$self->{attrs}}) : $self->{attrs};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 726 53 779
33 }
34  
35 142 my $name = $self->{name};
36 142 my @attrs = attrs_resolver($name);
37  
38 142 for my $base (@{$self->bases}) {
39 508 push @attrs, attrs_resolver($base);
40 }
41  
42 142 for my $role (@{$self->roles}) {
43 1702 push @attrs, attrs_resolver($role);
44 }
45  
46 142 my %seen;
47 142 ▶ my $results = $self->{attrs} ||= [grep !$seen{$_}++, @attrs];
Condition50%1/2
$self->{"attrs"} ||= [grep((!$seen{$_}++), @attrs)]
l!l
0142
MC/DC0%0/1
$self->{"attrs"} ||= [grep((!$seen{$_}++), @attrs)]
$self->{"attrs"}
Truth table50%1/2
A
A= $self->{"attrs"}
Aresult
11
00
48  
49 142 ▶ return wantarray ? (@$results) : $results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 52 90 142
50 }
51  
52 2355 ▶sub attrs_resolver {
Subroutine attrs_resolver: called CC=3 SCAR=11.0
Pod undocumented
53 2355 my ($name) = @_;
54  
55 120 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
56 120 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 2355 ▶ if (${"${name}::META"} && $${"${name}::META"}{ATTR}) {
Branch: 1 branch
BranchTrueFalseTotal
if (${"${name}::META";} and ${"${name}::META";}->{'ATTR'}) { } 169 2186 2355
Condition100%3/3
${"${name}::META";} and ${"${name}::META";}->{"ATTR"}
!ll&&!rl&&r
2841902169
MC/DC100%2/2
${"${name}::META";} and ${"${name}::META";}->{"ATTR"}
${"${name}::META";} ${"${name}::META";}->{"ATTR"}
Truth table100%3/3
A and B
A= ${"${name}::META";}B= ${"${name}::META";}->{"ATTR"}
ABresult
0X0
100
111
59 return (sort {
60 963 $${"${name}::META"}{ATTR}{$a}[0] <=> $${"${name}::META"}{ATTR}{$b}[0]
61 169 } keys %{$${"${name}::META"}{ATTR}});
62 }
63 else {
64 2186 return ();
65 }
66 }
67  
68 2 ▶sub base {
Subroutine base: called CC=3 SCAR=11.0
Pod documented
69 2 my ($self, $name) = @_;
70  
71 2 ▶ return 0 if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 2 2
72  
73 2 my $data = {map +($_,$_), @{$self->bases}};
74  
75 2 ▶ return $data->{$name} ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$data->{$name} ? : 1 1 2
76 }
77  
78 2 ▶sub mask {
Subroutine mask: called CC=3 SCAR=11.0
Pod documented
79 2 my ($self, $name) = @_;
80  
81 2 ▶ return 0 if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 2 2
82  
83 2 my $data = {map +($_,$_), @{$self->masks}};
84  
85 2 ▶ return $data->{$name} ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$data->{$name} ? : 1 1 2
86 }
87  
88 3 ▶sub masks {
Subroutine masks: called CC=7 SCAR=21.3
Pod documented
89 3 my ($self) = @_;
90  
91 3 ▶ if ($self->{masks}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"masks"}) 0 3 3
92 0 ▶ return wantarray ? (@{$self->{masks}}) : $self->{masks};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
93 }
94  
95 3 my $name = $self->{name};
96 3 my @masks = masks_resolver($name);
97  
98 3 for my $base (@{$self->bases}) {
99 9 push @masks, masks_resolver($base);
100 }
101  
102 3 for my $role (@{$self->roles}) {
103 6 push @masks, masks_resolver($role);
104 }
105  
106 3 my %seen;
107 3 ▶ my $results = $self->{masks} ||= [grep !$seen{$_}++, @masks];
Condition50%1/2
$self->{"masks"} ||= [grep((!$seen{$_}++), @masks)]
l!l
03
MC/DC0%0/1
$self->{"masks"} ||= [grep((!$seen{$_}++), @masks)]
$self->{"masks"}
Truth table50%1/2
A
A= $self->{"masks"}
Aresult
11
00
108  
109 3 ▶ return wantarray ? (@$results) : $results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
110 }
111  
112 18 ▶sub masks_resolver {
Subroutine masks_resolver: called CC=3 SCAR=11.1
Pod undocumented
113 18 my ($name) = @_;
114  
115 120 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
116 120 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
117  
118 18 ▶ if (${"${name}::META"} && $${"${name}::META"}{MASK}) {
Branch: 1 branch
BranchTrueFalseTotal
if (${"${name}::META";} and ${"${name}::META";}->{'MASK'}) { } 3 15 18
Condition100%3/3
${"${name}::META";} and ${"${name}::META";}->{"MASK"}
!ll&&!rl&&r
693
MC/DC100%2/2
${"${name}::META";} and ${"${name}::META";}->{"MASK"}
${"${name}::META";} ${"${name}::META";}->{"MASK"}
Truth table100%3/3
A and B
A= ${"${name}::META";}B= ${"${name}::META";}->{"MASK"}
ABresult
0X0
100
111
119 return (sort {
120 0 $${"${name}::META"}{MASK}{$a}[0] <=> $${"${name}::META"}{MASK}{$b}[0]
121 3 } keys %{$${"${name}::META"}{MASK}});
122 }
123 else {
124 15 return ();
125 }
126 }
127  
128 49459 ▶sub bases {
Subroutine bases: called CC=6 SCAR=17.9
Pod documented
129 49459 my ($self) = @_;
130  
131 49459 ▶ if ($self->{bases}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bases"}) 1677 47782 49459
132 1677 ▶ return wantarray ? (@{$self->{bases}}) : $self->{bases};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 1675 1677
133 }
134  
135 47782 my $name = $self->{name};
136 47782 my @bases = bases_resolver($name);
137  
138 47782 for my $base (@bases) {
139 333303 push @bases, bases_resolver($base);
140 }
141  
142 47782 my %seen;
143 47782 ▶ my $results = $self->{bases} ||= [grep !$seen{$_}++, @bases];
Condition50%1/2
$self->{"bases"} ||= [grep((!$seen{$_}++), @bases)]
l!l
047782
MC/DC0%0/1
$self->{"bases"} ||= [grep((!$seen{$_}++), @bases)]
$self->{"bases"}
Truth table50%1/2
A
A= $self->{"bases"}
Aresult
11
00
144  
145 47782 ▶ return wantarray ? (@$results) : $results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 135 47647 47782
146 }
147  
148 381087 ▶sub bases_resolver {
Subroutine bases_resolver: called CC=1 SCAR=0.0
Pod undocumented
149 381087 my ($name) = @_;
150  
151 120 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
152  
153 381087 return (@{"${name}::ISA"});
154 }
155  
156 1 ▶sub data {
Subroutine data: called CC=1 SCAR=0.0
Pod documented
157 1 my ($self) = @_;
158  
159 1 my $name = $self->{name};
160  
161 120 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
162  
163 1 return ${"${name}::META"};
164 }
165  
166 1 ▶sub emit {
Subroutine emit: called CC=1 SCAR=0.0
Pod documented
167 1 my ($self, $hook, @args) = @_;
168  
169 1 my $name = $self->{name};
170  
171 1 $hook = uc $hook;
172  
173 1 return $name->$hook(@args);
174 }
175  
176 4 ▶sub find {
Subroutine find: called CC=6 SCAR=18.0
Pod documented
177 4 my ($self, $type, $name) = @_;
178  
179 4 ▶ return if !$type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 1 3 4
180 3 ▶ return if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 3 3
181  
182 3 my $configs;
183  
184 3 for my $source (qw(roles bases mixins self)) {
185 6 $configs = $self->search($source, $type, $name);
186 6 ▶ last if @$configs;
Branch: 1 branch
BranchTrueFalseTotal
if @$configs 3 3 6
187 }
188  
189 3 ▶ return $configs ? $configs->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$configs ? : 3 0 3
190 }
191  
192 6 ▶sub local {
Subroutine local: called CC=4 SCAR=14.1
Pod documented
193 6 my ($self, $type) = @_;
194  
195 6 ▶ return if !$type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 6 6
196  
197 6 my $name = $self->{name};
198  
199 120 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
200  
201 6 ▶ return if !int grep $type eq $_, qw(attrs bases masks mixins roles subs);
Branch: 1 branch
BranchTrueFalseTotal
unless int grep(($type eq $_), ("attrs", "bases", "masks", "mixins", "roles", "subs")) 0 6 6
202  
203 6 my $function = "${type}_resolver";
204  
205 6 my $results = [&{"${function}"}($name)];
206  
207 6 ▶ return wantarray ? (@$results) : $results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 6 6
208 }
209  
210 8 ▶sub mixin {
Subroutine mixin: called CC=3 SCAR=11.0
Pod documented
211 8 my ($self, $name) = @_;
212  
213 8 ▶ return 0 if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 8 8
214  
215 8 my $data = {map +($_,$_), @{$self->mixins}};
216  
217 8 ▶ return $data->{$name} ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$data->{$name} ? : 7 1 8
218 }
219  
220 137106 ▶sub mixins {
Subroutine mixins: called CC=7 SCAR=19.9
Pod documented
221 137106 my ($self) = @_;
222  
223 137106 ▶ if ($self->{mixins}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"mixins"}) 135590 1516 137106
224 0 ▶ return wantarray ? (@{$self->{mixins}}) : $self->{mixins};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 135590 135590
225 }
226  
227 1516 my $name = $self->{name};
228 1516 my @mixins = mixins_resolver($name);
229  
230 1516 for my $mixin (@mixins) {
231 53 push @mixins, mixins_resolver($mixin);
232 }
233  
234 1516 for my $base (@{$self->bases}) {
235 5732 push @mixins, mixins_resolver($base);
236 }
237  
238 1516 my %seen;
239 1516 ▶ my $results = $self->{mixins} ||= [grep !$seen{$_}++, @mixins];
Condition50%1/2
$self->{"mixins"} ||= [grep((!$seen{$_}++), @mixins)]
l!l
01516
MC/DC0%0/1
$self->{"mixins"} ||= [grep((!$seen{$_}++), @mixins)]
$self->{"mixins"}
Truth table50%1/2
A
A= $self->{"mixins"}
Aresult
11
00
240  
241 1516 ▶ return wantarray ? (@$results) : $results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1516 1516
242 }
243  
244 7356 ▶sub mixins_resolver {
Subroutine mixins_resolver: called CC=3 SCAR=11.1
Pod undocumented
245 7356 my ($name) = @_;
246  
247 120 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
248  
249 7356 ▶ if (${"${name}::META"} && $${"${name}::META"}{MIXIN}) {
Branch: 1 branch
BranchTrueFalseTotal
if (${"${name}::META";} and ${"${name}::META";}->{'MIXIN'}) { } 54 7302 7356
Condition100%3/3
${"${name}::META";} and ${"${name}::META";}->{"MIXIN"}
!ll&&!rl&&r
3081422154
MC/DC100%2/2
${"${name}::META";} and ${"${name}::META";}->{"MIXIN"}
${"${name}::META";} ${"${name}::META";}->{"MIXIN"}
Truth table100%3/3
A and B
A= ${"${name}::META";}B= ${"${name}::META";}->{"MIXIN"}
ABresult
0X0
100
111
250 return (map +($_, mixins_resolver($_)), sort {
251 0 $${"${name}::META"}{MIXIN}{$a}[0] <=> $${"${name}::META"}{MIXIN}{$b}[0]
252 54 } keys %{$${"${name}::META"}{MIXIN}});
253 }
254 else {
255 7302 return ();
256 }
257 }
258  
259 47849 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
260 47849 my ($self, @args) = @_;
261  
262 47849 return $self->BLESS(@args);
263 }
264  
265 46256 ▶sub role {
Subroutine role: called CC=3 SCAR=11.0
Pod documented
266 46256 my ($self, $name) = @_;
267  
268 46256 ▶ return 0 if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 46256 46256
269  
270 46256 my $data = {map +($_,$_), @{$self->roles}};
271  
272 46256 ▶ return $data->{$name} ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$data->{$name} ? : 46225 31 46256
273 }
274  
275 252360 ▶sub roles {
Subroutine roles: called CC=7 SCAR=19.6
Pod documented
276 252360 my ($self) = @_;
277  
278 252360 ▶ if ($self->{roles}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"roles"}) 204714 47646 252360
279 0 ▶ return wantarray ? (@{$self->{roles}}) : $self->{roles};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 204714 204714
280 }
281  
282 47646 my $name = $self->{name};
283 47646 my @roles = roles_resolver($name);
284  
285 47646 for my $role (@roles) {
286 75473 push @roles, roles_resolver($role);
287 }
288  
289 47646 for my $base (@{$self->bases}) {
290 180292 push @roles, roles_resolver($base);
291 }
292  
293 47646 my %seen;
294 47646 ▶ my $results = $self->{roles} ||= [grep !$seen{$_}++, @roles];
Condition50%1/2
$self->{"roles"} ||= [grep((!$seen{$_}++), @roles)]
l!l
047646
MC/DC0%0/1
$self->{"roles"} ||= [grep((!$seen{$_}++), @roles)]
$self->{"roles"}
Truth table50%1/2
A
A= $self->{"roles"}
Aresult
11
00
295  
296 47646 ▶ return wantarray ? (@$results) : $results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 47645 47646
297 }
298  
299 1179066 ▶sub roles_resolver {
Subroutine roles_resolver: called CC=3 SCAR=11.0
Pod undocumented
300 1179066 my ($name) = @_;
301  
302 120 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
303 120 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
304  
305 1179066 ▶ if (${"${name}::META"} && $${"${name}::META"}{ROLE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (${"${name}::META";} and ${"${name}::META";}->{'ROLE'}) { } 121281 1057785 1179066
Condition100%3/3
${"${name}::META";} and ${"${name}::META";}->{"ROLE"}
!ll&&!rl&&r
104014953771121281
MC/DC100%2/2
${"${name}::META";} and ${"${name}::META";}->{"ROLE"}
${"${name}::META";} ${"${name}::META";}->{"ROLE"}
Truth table100%3/3
A and B
A= ${"${name}::META";}B= ${"${name}::META";}->{"ROLE"}
ABresult
0X0
100
111
306 return (map +($_, roles_resolver($_)), sort {
307 2192474 $${"${name}::META"}{ROLE}{$a}[0] <=> $${"${name}::META"}{ROLE}{$b}[0]
308 121281 } keys %{$${"${name}::META"}{ROLE}});
309 }
310 else {
311 1057785 return ();
312 }
313 }
314  
315 10 ▶sub search {
Subroutine search: called CC=12 SCAR=24.9
Pod documented
316 10 my ($self, $from, $type, $name) = @_;
317  
318 10 ▶ return if !$from;
Branch: 1 branch
BranchTrueFalseTotal
unless $from 1 9 10
319 9 ▶ return if !$type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 9 9
320 9 ▶ return if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 9 9
321  
322 120 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
323  
324 9 my @configs;
325 my @sources;
326  
327 9 ▶ if (lc($from) eq 'bases') {
Branch: 3 branches
BranchTrueFalseTotal
if (lc $from eq 'bases') { } 1 8 9
elsif (lc $from eq 'roles') { } 4 4 8
elsif (lc $from eq 'mixins') { } 1 3 4
328 1 @sources = bases_resolver($self->{name});
329 }
330 elsif (lc($from) eq 'roles') {
331 4 @sources = roles_resolver($self->{name});
332 }
333 elsif (lc($from) eq 'mixins') {
334 1 @sources = mixins_resolver($self->{name});
335 }
336 else {
337 3 @sources = ($self->{name});
338 }
339  
340 9 for my $source (@sources) {
341 14 ▶ if (lc($type) eq 'sub') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $type eq 'sub') { } 10 4 14
342 10 ▶ if (*{"${source}::${name}"}{"CODE"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*{"${source}::$name";}{"CODE"}) 4 6 10
343 4 push @configs, [$source, [1, [*{"${source}::${name}"}{"CODE"}]]];
344 }
345 }
346 else {
347 4 ▶ if ($${"${source}::META"}{uc($type)}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($${"${source}::META";}{uc $type}{$name}) 2 2 4
348 2 push @configs, [$source, $${"${source}::META"}{uc($type)}{$name}];
349 }
350 }
351 }
352  
353 9 my $results = [@configs];
354  
355 9 ▶ return wantarray ? (@$results) : $results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 9 9
356 }
357  
358 3 ▶sub sub {
Subroutine sub: called CC=3 SCAR=11.0
Pod documented
359 3 my ($self, $name) = @_;
360  
361 3 ▶ return 0 if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 3 3
362  
363 3 my $data = {map +($_,$_), @{$self->subs}};
364  
365 3 ▶ return $data->{$name} ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$data->{$name} ? : 2 1 3
366 }
367  
368 70 ▶sub subs {
Subroutine subs: called CC=6 SCAR=18.0
Pod documented
369 70 my ($self) = @_;
370  
371 70 ▶ if ($self->{subs}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"subs"}) 59 11 70
372 59 ▶ return wantarray ? (@{$self->{subs}}) : $self->{subs};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 59 0 59
373 }
374  
375 11 my $name = $self->{name};
376 11 my @subs = subs_resolver($name);
377  
378 11 for my $base (@{$self->bases}) {
379 29 push @subs, subs_resolver($base);
380 }
381  
382 11 my %seen;
383 11 ▶ my $results = $self->{subs} ||= [grep !$seen{$_}++, @subs];
Condition50%1/2
$self->{"subs"} ||= [grep((!$seen{$_}++), @subs)]
l!l
011
MC/DC0%0/1
$self->{"subs"} ||= [grep((!$seen{$_}++), @subs)]
$self->{"subs"}
Truth table50%1/2
A
A= $self->{"subs"}
Aresult
11
00
384  
385 11 ▶ return wantarray ? (@$results) : $results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 4 11
386 }
387  
388 41 ▶sub subs_resolver {
Subroutine subs_resolver: called CC=1 SCAR=0.0
Pod undocumented
389 41 my ($name) = @_;
390  
391 120 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
392  
393 return (
394 1237 grep *{"${name}::$_"}{"CODE"},
395 41 grep /^[_a-zA-Z]\w*$/, keys %{"${name}::"}
396 );
397 }
398  
399 120 1;
400  
401  
402  
403 =head1 NAME
404  
405 Venus::Meta - Class Metadata
406  
407 =cut
408  
409 =head1 ABSTRACT
410  
411 Class Metadata for Perl 5
412  
413 =cut
414  
415 =head1 SYNOPSIS
416  
417 package Person;
418  
419 use Venus::Class;
420  
421 attr 'fname';
422 attr 'lname';
423  
424 package Identity;
425  
426 use Venus::Role;
427  
428 attr 'id';
429 attr 'login';
430 attr 'password';
431  
432 sub EXPORT {
433 # explicitly declare routines to be consumed
434 ['id', 'login', 'password']
435 }
436  
437 package Authenticable;
438  
439 use Venus::Role;
440  
441 mask 'auth_token';
442  
443 sub authenticate {
444 return true;
445 }
446  
447 sub AUDIT {
448 my ($self, $from) = @_;
449 # ensure the caller has a login and password when consumed
450 die "${from} missing the login attribute" if !$from->can('login');
451 die "${from} missing the password attribute" if !$from->can('password');
452 }
453  
454 sub EXPORT {
455 # explicitly declare routines to be consumed
456 ['auth_token', 'authenticate']
457 }
458  
459 package Novice;
460  
461 use Venus::Mixin;
462  
463 sub points {
464 100
465 }
466  
467 package User;
468  
469 use Venus::Class 'attr', 'base', 'mixin', 'test', 'with';
470  
471 base 'Person';
472  
473 with 'Identity';
474  
475 mixin 'Novice';
476  
477 attr 'email';
478  
479 test 'Authenticable';
480  
481 sub valid {
482 my ($self) = @_;
483 return $self->login && $self->password ? true : false;
484 }
485  
486 package main;
487  
488 my $user = User->new(
489 fname => 'Elliot',
490 lname => 'Alderson',
491 );
492  
493 my $meta = $user->meta;
494  
495 # bless({name => 'User'}, 'Venus::Meta')
496  
497 =cut
498  
499 =head1 DESCRIPTION
500  
501 This package provides configuration information for L<Venus> derived classes,
502 roles, and interfaces.
503  
504 =cut
505  
506 =head1 METHODS
507  
508 This package provides the following methods:
509  
510 =cut
511  
512 =head2 attr
513  
514 attr(string $name) (boolean)
515  
516 The attr method returns true or false if the package referenced has the
517 attribute accessor named.
518  
519 I<Since C<1.00>>
520  
521 =over 4
522  
523 =item attr example 1
524  
525 # given: synopsis
526  
527 package main;
528  
529 my $attr = $meta->attr('email');
530  
531 # 1
532  
533 =back
534  
535 =over 4
536  
537 =item attr example 2
538  
539 # given: synopsis
540  
541 package main;
542  
543 my $attr = $meta->attr('username');
544  
545 # 0
546  
547 =back
548  
549 =cut
550  
551 =head2 attrs
552  
553 attrs() (arrayref)
554  
555 The attrs method returns all of the attributes composed into the package
556 referenced.
557  
558 I<Since C<1.00>>
559  
560 =over 4
561  
562 =item attrs example 1
563  
564 # given: synopsis
565  
566 package main;
567  
568 my $attrs = $meta->attrs;
569  
570 # [
571 # 'email',
572 # 'fname',
573 # 'id',
574 # 'lname',
575 # 'login',
576 # 'password',
577 # ]
578  
579 =back
580  
581 =cut
582  
583 =head2 base
584  
585 base(string $name) (boolean)
586  
587 The base method returns true or false if the package referenced has inherited
588 the package named.
589  
590 I<Since C<1.00>>
591  
592 =over 4
593  
594 =item base example 1
595  
596 # given: synopsis
597  
598 package main;
599  
600 my $base = $meta->base('Person');
601  
602 # 1
603  
604 =back
605  
606 =over 4
607  
608 =item base example 2
609  
610 # given: synopsis
611  
612 package main;
613  
614 my $base = $meta->base('Student');
615  
616 # 0
617  
618 =back
619  
620 =cut
621  
622 =head2 bases
623  
624 bases() (arrayref)
625  
626 The bases method returns returns all of the packages inherited by the package
627 referenced.
628  
629 I<Since C<1.00>>
630  
631 =over 4
632  
633 =item bases example 1
634  
635 # given: synopsis
636  
637 package main;
638  
639 my $bases = $meta->bases;
640  
641 # [
642 # 'Person',
643 # 'Venus::Core::Class',
644 # 'Venus::Core',
645 # ]
646  
647 =back
648  
649 =cut
650  
651 =head2 data
652  
653 data() (hashref)
654  
655 The data method returns a data structure representing the shallow configuration
656 for the package referenced.
657  
658 I<Since C<1.00>>
659  
660 =over 4
661  
662 =item data example 1
663  
664 # given: synopsis
665  
666 package main;
667  
668 my $data = $meta->data;
669  
670 # {
671 # 'ATTR' => {
672 # 'email' => [
673 # 'email'
674 # ]
675 # },
676 # 'BASE' => {
677 # 'Person' => [
678 # 'Person'
679 # ]
680 # },
681 # 'ROLE' => {
682 # 'Authenticable' => [
683 # 'Authenticable'
684 # ],
685 # 'Identity' => [
686 # 'Identity'
687 # ]
688 # }
689 # }
690  
691 =back
692  
693 =cut
694  
695 =head2 emit
696  
697 emit(string $name, any @args) (any)
698  
699 The emit method invokes the lifecycle hook specified on the underlying package
700 and returns the result.
701  
702 I<Since C<2.91>>
703  
704 =over 4
705  
706 =item emit example 1
707  
708 # given: synopsis
709  
710 package main;
711  
712 my $result = $meta->emit('attr', 'mname');
713  
714 # "User"
715  
716 =back
717  
718 =cut
719  
720 =head2 find
721  
722 find(string $type, string $name) (tuple[string,tuple[number,arrayref]])
723  
724 The find method finds and returns the first configuration for the property type
725 specified. This method uses the L</search> method to search C<roles>, C<bases>,
726 C<mixins>, and the source package, in the order listed. The "property type" can
727 be any one of C<attr>, C<base>, C<mixin>, or C<role>.
728  
729 I<Since C<1.02>>
730  
731 =over 4
732  
733 =item find example 1
734  
735 # given: synopsis
736  
737 package main;
738  
739 my $find = $meta->find;
740  
741 # ()
742  
743 =back
744  
745 =over 4
746  
747 =item find example 2
748  
749 # given: synopsis
750  
751 package main;
752  
753 my $find = $meta->find('attr', 'id');
754  
755 # ['Identity', [ 1, ['id']]]
756  
757 =back
758  
759 =over 4
760  
761 =item find example 3
762  
763 # given: synopsis
764  
765 package main;
766  
767 my $find = $meta->find('sub', 'valid');
768  
769 # ['User', [1, [sub {...}]]]
770  
771 =back
772  
773 =over 4
774  
775 =item find example 4
776  
777 # given: synopsis
778  
779 package main;
780  
781 my $find = $meta->find('sub', 'authenticate');
782  
783 # ['Authenticable', [1, [sub {...}]]]
784  
785 =back
786  
787 =cut
788  
789 =head2 local
790  
791 local(string $type) (arrayref)
792  
793 The local method returns the names of properties defined in the package
794 directly (not inherited) for the property type specified. The C<$type> provided
795 can be either C<attrs>, C<bases>, C<masks>, C<roles>, or C<subs>.
796  
797 I<Since C<1.02>>
798  
799 =over 4
800  
801 =item local example 1
802  
803 # given: synopsis
804  
805 package main;
806  
807 my $attrs = $meta->local('attrs');
808  
809 # ['email']
810  
811 =back
812  
813 =over 4
814  
815 =item local example 2
816  
817 # given: synopsis
818  
819 package main;
820  
821 my $bases = $meta->local('bases');
822  
823 # ['Person', 'Venus::Core::Class']
824  
825 =back
826  
827 =over 4
828  
829 =item local example 3
830  
831 # given: synopsis
832  
833 package main;
834  
835 my $roles = $meta->local('roles');
836  
837 # ['Identity', 'Authenticable']
838  
839 =back
840  
841 =over 4
842  
843 =item local example 4
844  
845 # given: synopsis
846  
847 package main;
848  
849 my $subs = $meta->local('subs');
850  
851 # [
852 # 'attr',
853 # 'auth_token',
854 # 'authenticate',
855 # 'base',
856 # 'email',
857 # 'false',
858 # 'id',
859 # 'login',
860 # 'password',
861 # 'test',
862 # 'true',
863 # 'valid',
864 # 'with',
865 # ]
866  
867 =back
868  
869 =cut
870  
871 =head2 mask
872  
873 mask(string $name) (boolean)
874  
875 The mask method returns true or false if the package referenced has the
876 private attribute accessor named.
877  
878 I<Since C<4.15>>
879  
880 =over 4
881  
882 =item mask example 1
883  
884 # given: synopsis
885  
886 package main;
887  
888 my $mask = $meta->mask('auth_token');
889  
890 # 1
891  
892 =back
893  
894 =over 4
895  
896 =item mask example 2
897  
898 # given: synopsis
899  
900 package main;
901  
902 my $mask = $meta->mask('username');
903  
904 # 0
905  
906 =back
907  
908 =cut
909  
910 =head2 masks
911  
912 masks() (arrayref)
913  
914 The masks method returns all of the private attributes composed into the
915 package referenced.
916  
917 I<Since C<4.15>>
918  
919 =over 4
920  
921 =item masks example 1
922  
923 # given: synopsis
924  
925 package main;
926  
927 my $masks = $meta->masks;
928  
929 # ['auth_token']
930  
931 =back
932  
933 =cut
934  
935 =head2 mixin
936  
937 mixin(string $name) (boolean)
938  
939 The mixin method returns true or false if the package referenced has consumed
940 the mixin named.
941  
942 I<Since C<1.02>>
943  
944 =over 4
945  
946 =item mixin example 1
947  
948 # given: synopsis
949  
950 package main;
951  
952 my $mixin = $meta->mixin('Novice');
953  
954 # 1
955  
956 =back
957  
958 =over 4
959  
960 =item mixin example 2
961  
962 # given: synopsis
963  
964 package main;
965  
966 my $mixin = $meta->mixin('Intermediate');
967  
968 # 0
969  
970 =back
971  
972 =cut
973  
974 =head2 mixins
975  
976 mixins() (arrayref)
977  
978 The mixins method returns all of the mixins composed into the package
979 referenced.
980  
981 I<Since C<1.02>>
982  
983 =over 4
984  
985 =item mixins example 1
986  
987 # given: synopsis
988  
989 package main;
990  
991 my $mixins = $meta->mixins;
992  
993 # [
994 # 'Novice',
995 # ]
996  
997 =back
998  
999 =cut
1000  
1001 =head2 new
1002  
1003 new(any %args | hashref $args) (object)
1004  
1005 The new method returns a new instance of this package.
1006  
1007 I<Since C<1.00>>
1008  
1009 =over 4
1010  
1011 =item new example 1
1012  
1013 # given: synopsis
1014  
1015 package main;
1016  
1017 $meta = Venus::Meta->new(name => 'User');
1018  
1019 # bless({name => 'User'}, 'Venus::Meta')
1020  
1021 =back
1022  
1023 =over 4
1024  
1025 =item new example 2
1026  
1027 # given: synopsis
1028  
1029 package main;
1030  
1031 $meta = Venus::Meta->new({name => 'User'});
1032  
1033 # bless({name => 'User'}, 'Venus::Meta')
1034  
1035 =back
1036  
1037 =cut
1038  
1039 =head2 role
1040  
1041 role(string $name) (boolean)
1042  
1043 The role method returns true or false if the package referenced has consumed
1044 the role named.
1045  
1046 I<Since C<1.00>>
1047  
1048 =over 4
1049  
1050 =item role example 1
1051  
1052 # given: synopsis
1053  
1054 package main;
1055  
1056 my $role = $meta->role('Identity');
1057  
1058 # 1
1059  
1060 =back
1061  
1062 =over 4
1063  
1064 =item role example 2
1065  
1066 # given: synopsis
1067  
1068 package main;
1069  
1070 my $role = $meta->role('Builder');
1071  
1072 # 0
1073  
1074 =back
1075  
1076 =cut
1077  
1078 =head2 roles
1079  
1080 roles() (arrayref)
1081  
1082 The roles method returns all of the roles composed into the package referenced.
1083  
1084 I<Since C<1.00>>
1085  
1086 =over 4
1087  
1088 =item roles example 1
1089  
1090 # given: synopsis
1091  
1092 package main;
1093  
1094 my $roles = $meta->roles;
1095  
1096 # [
1097 # 'Identity',
1098 # 'Authenticable'
1099 # ]
1100  
1101 =back
1102  
1103 =cut
1104  
1105 =head2 search
1106  
1107 search(string $from, string $type, string $name) (within[arrayref, tuple[string,tuple[number,arrayref]]])
1108  
1109 The search method searches the source specified and returns the configurations
1110 for the property type specified. The source can be any one of C<bases>,
1111 C<roles>, C<mixins>, or C<self> for the source package. The "property type" can
1112 be any one of C<attr>, C<base>, C<mixin>, or C<role>.
1113  
1114 I<Since C<1.02>>
1115  
1116 =over 4
1117  
1118 =item search example 1
1119  
1120 # given: synopsis
1121  
1122 package main;
1123  
1124 my $search = $meta->search;
1125  
1126 # ()
1127  
1128 =back
1129  
1130 =over 4
1131  
1132 =item search example 2
1133  
1134 # given: synopsis
1135  
1136 package main;
1137  
1138 my $search = $meta->search('roles', 'attr', 'id');
1139  
1140 # [['Identity', [ 1, ['id']]]]
1141  
1142 =back
1143  
1144 =over 4
1145  
1146 =item search example 3
1147  
1148 # given: synopsis
1149  
1150 package main;
1151  
1152 my $search = $meta->search('self', 'sub', 'valid');
1153  
1154 # [['User', [1, [sub {...}]]]]
1155  
1156 =back
1157  
1158 =over 4
1159  
1160 =item search example 4
1161  
1162 # given: synopsis
1163  
1164 package main;
1165  
1166 my $search = $meta->search('self', 'sub', 'authenticate');
1167  
1168 # [['User', [1, [sub {...}]]]]
1169  
1170 =back
1171  
1172 =cut
1173  
1174 =head2 sub
1175  
1176 sub(string $name) (boolean)
1177  
1178 The sub method returns true or false if the package referenced has the
1179 subroutine named on the package directly, or any of its superclasses.
1180  
1181 I<Since C<1.00>>
1182  
1183 =over 4
1184  
1185 =item sub example 1
1186  
1187 # given: synopsis
1188  
1189 package main;
1190  
1191 my $sub = $meta->sub('authenticate');
1192  
1193 # 1
1194  
1195 =back
1196  
1197 =over 4
1198  
1199 =item sub example 2
1200  
1201 # given: synopsis
1202  
1203 package main;
1204  
1205 my $sub = $meta->sub('authorize');
1206  
1207 # 0
1208  
1209 =back
1210  
1211 =cut
1212  
1213 =head2 subs
1214  
1215 subs() (arrayref)
1216  
1217 The subs method returns all of the subroutines composed into the package
1218 referenced.
1219  
1220 I<Since C<1.00>>
1221  
1222 =over 4
1223  
1224 =item subs example 1
1225  
1226 # given: synopsis
1227  
1228 package main;
1229  
1230 my $subs = $meta->subs;
1231  
1232 # [
1233 # 'attr', ...,
1234 # 'base',
1235 # 'email',
1236 # 'false',
1237 # 'fname', ...,
1238 # 'id',
1239 # 'lname',
1240 # 'login',
1241 # 'new', ...,
1242 # 'role',
1243 # 'test',
1244 # 'true',
1245 # 'with', ...,
1246 # ]
1247  
1248 =back
1249  
1250 =cut
1251  
1252 =head1 AUTHORS
1253  
1254 Awncorp, C<awncorp@cpan.org>
1255  
1256 =cut
1257  
1258 =head1 LICENSE
1259  
1260 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
1261  
1262 This program is free software, you can redistribute it and/or modify it under
1263 the terms of the Apache license version 2.0.
1264  
1265 =cut
« blib/lib/Venus/Role/Optional.pm ↑ Summary blib/lib/Venus/Task.pm »