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