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