| 1 | package Mars::Kind::Class; | ||
| 2 | |||
| 3 | 7 | ▶ | use 5.018; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 7 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 7 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 7 | ▶ | use base 'Mars::Kind'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | # METHODS | ||
| 11 | |||
| 12 | 44 | ▶ | sub BUILD { |
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
documented
| |||
| 13 | 44 | my ($self, @data) = @_; | |
| 14 | |||
| 15 | 7 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | |||
| 17 | 44 | my @roles = @{$self->META->roles}; | |
| 18 | |||
| 19 | 44 | for my $action (grep defined, map *{"${_}::BUILD"}{"CODE"}, @roles) { | |
| 20 | 3 | $self->$action(@data); | |
| 21 | } | ||
| 22 | |||
| 23 | 44 | return $self; | |
| 24 | } | ||
| 25 | |||
| 26 | 44 | ▶ | sub DESTROY { |
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
| |||
| 27 | 44 | my ($self, @data) = @_; | |
| 28 | |||
| 29 | 7 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 30 | |||
| 31 | 44 | my @roles = @{$self->META->roles}; | |
| 32 | |||
| 33 | 44 | for my $action (grep defined, map *{"${_}::DESTROY"}{"CODE"}, @roles) { | |
| 34 | 1 | $self->$action(@data); | |
| 35 | } | ||
| 36 | |||
| 37 | 44 | return $self; | |
| 38 | } | ||
| 39 | |||
| 40 | 27 | ▶ | sub does { |
|
Subroutine
does: called CC=1 SCAR=0.0
Pod
documented
| |||
| 41 | 27 | my ($self, @args) = @_; | |
| 42 | |||
| 43 | 27 | return $self->DOES(@args); | |
| 44 | } | ||
| 45 | |||
| 46 | 18 | ▶ | sub meta { |
|
Subroutine
meta: called CC=1 SCAR=0.0
Pod
documented
| |||
| 47 | 18 | my ($self) = @_; | |
| 48 | |||
| 49 | 18 | return $self->META; | |
| 50 | } | ||
| 51 | |||
| 52 | 43 | ▶ | sub new { |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||
| 53 | 43 | my ($self, @args) = @_; | |
| 54 | |||
| 55 | 43 | return $self->BLESS(@args); | |
| 56 | } | ||
| 57 | |||
| 58 | 7 | 1; | |
| 59 | |||
| 60 | |||
| 61 | |||
| 62 | =head1 NAME | ||
| 63 | |||
| 64 | Mars::Kind::Class - Class Base Class | ||
| 65 | |||
| 66 | =cut | ||
| 67 | |||
| 68 | =head1 ABSTRACT | ||
| 69 | |||
| 70 | Class Base Class for Perl 5 | ||
| 71 | |||
| 72 | =cut | ||
| 73 | |||
| 74 | =head1 SYNOPSIS | ||
| 75 | |||
| 76 | package User; | ||
| 77 | |||
| 78 | use base 'Mars::Kind::Class'; | ||
| 79 | |||
| 80 | package main; | ||
| 81 | |||
| 82 | my $user = User->new( | ||
| 83 | fname => 'Elliot', | ||
| 84 | lname => 'Alderson', | ||
| 85 | ); | ||
| 86 | |||
| 87 | # bless({fname => 'Elliot', lname => 'Alderson'}, 'User') | ||
| 88 | |||
| 89 | =cut | ||
| 90 | |||
| 91 | =head1 DESCRIPTION | ||
| 92 | |||
| 93 | This package provides a class base class with class building and object | ||
| 94 | construction lifecycle hooks. | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | =head1 INHERITS | ||
| 99 | |||
| 100 | This package inherits behaviors from: | ||
| 101 | |||
| 102 | L<Mars::Kind> | ||
| 103 | |||
| 104 | =cut | ||
| 105 | |||
| 106 | =head1 METHODS | ||
| 107 | |||
| 108 | This package provides the following methods: | ||
| 109 | |||
| 110 | =cut | ||
| 111 | |||
| 112 | =head2 does | ||
| 113 | |||
| 114 | does(Str $name) (Bool) | ||
| 115 | |||
| 116 | The does method returns true if the object is composed of the role provided. | ||
| 117 | |||
| 118 | I<Since C<0.01>> | ||
| 119 | |||
| 120 | =over 4 | ||
| 121 | |||
| 122 | =item does example 1 | ||
| 123 | |||
| 124 | # given: synopsis | ||
| 125 | |||
| 126 | my $does = $user->does('Identity'); | ||
| 127 | |||
| 128 | # 0 | ||
| 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 | # given: synopsis | ||
| 148 | |||
| 149 | package main; | ||
| 150 | |||
| 151 | my $user = User->new( | ||
| 152 | fname => 'Elliot', | ||
| 153 | lname => 'Alderson', | ||
| 154 | ); | ||
| 155 | |||
| 156 | my $meta = $user->meta; | ||
| 157 | |||
| 158 | # bless({...}, 'Mars::Meta') | ||
| 159 | |||
| 160 | =back | ||
| 161 | |||
| 162 | =cut | ||
| 163 | |||
| 164 | =head2 new | ||
| 165 | |||
| 166 | new(Any %args | HashRef $args) (Object) | ||
| 167 | |||
| 168 | The new method instantiates the class and returns a new object. | ||
| 169 | |||
| 170 | I<Since C<0.01>> | ||
| 171 | |||
| 172 | =over 4 | ||
| 173 | |||
| 174 | =item new example 1 | ||
| 175 | |||
| 176 | package main; | ||
| 177 | |||
| 178 | my $user = User->new( | ||
| 179 | fname => 'Elliot', | ||
| 180 | lname => 'Alderson', | ||
| 181 | ); | ||
| 182 | |||
| 183 | # bless({fname => 'Elliot', lname => 'Alderson'}, 'User') | ||
| 184 | |||
| 185 | =back | ||
| 186 | |||
| 187 | =over 4 | ||
| 188 | |||
| 189 | =item new example 2 | ||
| 190 | |||
| 191 | package main; | ||
| 192 | |||
| 193 | my $user = User->new({ | ||
| 194 | fname => 'Elliot', | ||
| 195 | lname => 'Alderson', | ||
| 196 | }); | ||
| 197 | |||
| 198 | # bless({fname => 'Elliot', lname => 'Alderson'}, 'User') | ||
| 199 | |||
| 200 | =back | ||
| 201 | |||
| 202 | =cut | ||
| 203 | |||
| 204 | =head1 AUTHORS | ||
| 205 | |||
| 206 | Awncorp, C<awncorp@cpan.org> | ||
| 207 | |||
| 208 | =cut | ||