Mars/Kind/Role.pm

filter: Statementstmt 73.5% 39 / 53 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 12 / 14 Podpod 100% 5 / 5 totaltotal 77.7% 56 / 72 CC 4 SCAR 5.2
CC
4
Cov
74%
BUILD
3.4
DESTROY
3.4
IMPORT
2.0
CRAP 1.7
« Mars/Kind.pm ↑ Summary Mars.pm »
1 package Mars::Kind::Role;
2  
3 6 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶use base 'Mars::Kind';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # METHODS
11  
12 0 ▶sub BUILD {
Subroutine BUILD: not called CC=2 SCAR=12.2
Pod documented
13 0 my ($self, @data) = @_;
14  
15 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 0 my @roles = @{$self->META->roles};
18  
19 0 for my $action (grep defined, map *{"${_}::BUILD"}{"CODE"}, @roles) {
20 0 $self->$action(@data);
21 }
22  
23 0 return $self;
24 }
25  
26 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=12.2
27 0 my ($self, @data) = @_;
28  
29 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 0 my @roles = @{$self->META->roles};
32  
33 0 for my $action (grep defined, map *{"${_}::DESTROY"}{"CODE"}, @roles) {
34 0 $self->$action(@data);
35 }
36  
37 0 return $self;
38 }
39  
40 17 ▶sub EXPORT {
Subroutine EXPORT: called CC=1 SCAR=0.0
Pod documented
41 17 my ($self, $into) = @_;
42  
43 17 return [];
44 }
45  
46 32 ▶sub IMPORT {
Subroutine IMPORT: called CC=2 SCAR=6.9
Pod documented
47 32 my ($self, $into) = @_;
48  
49 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
50 6 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 32 for my $name (grep !*{"${into}::${_}"}{"CODE"}, @{$self->EXPORT($into)}) {
53 23 *{"${into}::${name}"} = \&{"@{[$self->NAME]}::${name}"};
54 }
55  
56 32 return $self;
57 }
58  
59 1 ▶sub does {
Subroutine does: called CC=1 SCAR=0.0
Pod documented
60 1 my ($self, @args) = @_;
61  
62 1 return $self->DOES(@args);
63 }
64  
65 1 ▶sub meta {
Subroutine meta: called CC=1 SCAR=0.0
Pod documented
66 1 my ($self) = @_;
67  
68 1 return $self->META;
69 }
70  
71 6 1;
72  
73  
74  
75 =head1 NAME
76  
77 Mars::Kind::Role - Role Base Class
78  
79 =cut
80  
81 =head1 ABSTRACT
82  
83 Role Base Class for Perl 5
84  
85 =cut
86  
87 =head1 SYNOPSIS
88  
89 package Person;
90  
91 use base 'Mars::Kind::Role';
92  
93 package User;
94  
95 use base 'Mars::Kind::Class';
96  
97 package main;
98  
99 my $user = User->ROLE('Person')->new(
100 fname => 'Elliot',
101 lname => 'Alderson',
102 );
103  
104 # bless({fname => 'Elliot', lname => 'Alderson'}, 'User')
105  
106 =cut
107  
108 =head1 DESCRIPTION
109  
110 This package provides a role base class with role building and object
111 construction lifecycle hooks.
112  
113 =cut
114  
115 =head1 INHERITS
116  
117 This package inherits behaviors from:
118  
119 L<Mars::Kind>
120  
121 =cut
122  
123 =head1 METHODS
124  
125 This package provides the following methods:
126  
127 =cut
128  
129 =head2 does
130  
131 does(Str $name) (Bool)
132  
133 The does method returns true if the object is composed of the role provided.
134  
135 I<Since C<0.01>>
136  
137 =over 4
138  
139 =item does example 1
140  
141 package Employee;
142  
143 use base 'Mars::Kind::Role';
144  
145 Employee->ROLE('Person');
146  
147 package main;
148  
149 my $user = User->ROLE('Employee')->new(
150 fname => 'Elliot',
151 lname => 'Alderson',
152 );
153  
154 my $does = Employee->does('Person');
155  
156 # 1
157  
158 =back
159  
160 =cut
161  
162 =head2 meta
163  
164 meta() (Meta)
165  
166 The meta method returns a L<Mars::Meta> objects which describes the package's
167 configuration.
168  
169 I<Since C<0.01>>
170  
171 =over 4
172  
173 =item meta example 1
174  
175 package main;
176  
177 my $user = User->ROLE('Person')->new(
178 fname => 'Elliot',
179 lname => 'Alderson',
180 );
181  
182 my $meta = Person->meta;
183  
184 # bless({...}, 'Mars::Meta')
185  
186 =back
187  
188 =cut
189  
190 =head1 AUTHORS
191  
192 Awncorp, C<awncorp@cpan.org>
193  
194 =cut
« Mars/Kind.pm ↑ Summary Mars.pm »