| 1 | package Venus::Core::Role; | ||
| 2 | |||
| 3 | 96 | ▶ | use 5.018; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 96 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 96 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 96 | ▶ | no warnings 'once'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 96 | ▶ | use base 'Venus::Core'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | # METHODS | ||
| 13 | |||
| 14 | sub BUILD { | ||
| 15 | 0 | ▶ | my ($self, @data) = @_; |
|
Subroutine
BUILD: not called CC=2 SCAR=12.2
Pod
undocumented
| |||
| 16 | |||
| 17 | 96 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | |||
| 19 | 0 | my @roles = @{$self->META->roles}; | |
| 20 | |||
| 21 | 0 | for my $action (grep defined, map *{"${_}::BUILD"}{"CODE"}, @roles) { | |
| 22 | 0 | $self->$action(@data); | |
| 23 | } | ||
| 24 | |||
| 25 | 0 | return $self; | |
| 26 | } | ||
| 27 | |||
| 28 | sub DESTROY { | ||
| 29 | 0 | ▶ | my ($self, @data) = @_; |
|
Subroutine
DESTROY: not called CC=3 SCAR=20.3
| |||
| 30 | |||
| 31 | 96 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 32 | |||
| 33 | 0 | my @mixins = @{$self->META->mixins}; | |
| 34 | |||
| 35 | 0 | for my $action (grep defined, map *{"${_}::DESTROY"}{"CODE"}, @mixins) { | |
| 36 | 0 | $self->$action(@data); | |
| 37 | } | ||
| 38 | |||
| 39 | 0 | my @roles = @{$self->META->roles}; | |
| 40 | |||
| 41 | 0 | for my $action (grep defined, map *{"${_}::DESTROY"}{"CODE"}, @roles) { | |
| 42 | 0 | $self->$action(@data); | |
| 43 | } | ||
| 44 | |||
| 45 | 0 | return $self; | |
| 46 | } | ||
| 47 | |||
| 48 | sub EXPORT { | ||
| 49 | 255 | ▶ | my ($self, $into) = @_; |
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 50 | |||
| 51 | 255 | return []; | |
| 52 | } | ||
| 53 | |||
| 54 | sub IMPORT { | ||
| 55 | 3306 | ▶ | my ($self, $into) = @_; |
|
Subroutine
IMPORT: called CC=2 SCAR=6.9
Pod
undocumented
| |||
| 56 | |||
| 57 | 96 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 58 | 96 | ▶ | no warnings 'redefine'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 59 | |||
| 60 | 3306 | for my $name (grep !*{"${into}::${_}"}{"CODE"}, @{$self->EXPORT($into)}) { | |
| 61 | 7423 | *{"${into}::${name}"} = \&{"@{[$self->NAME]}::${name}"}; | |
| 62 | } | ||
| 63 | |||
| 64 | 3306 | return $self; | |
| 65 | } | ||
| 66 | |||
| 67 | sub does { | ||
| 68 | 1 | ▶ | my ($self, @args) = @_; |
|
Subroutine
does: called CC=1 SCAR=0.0
Pod
documented
| |||
| 69 | |||
| 70 | 1 | return $self->DOES(@args); | |
| 71 | } | ||
| 72 | |||
| 73 | sub import { | ||
| 74 | 0 | ▶ | my ($self) = @_; |
|
Subroutine
import: not called CC=1 SCAR=6.9
| |||
| 75 | |||
| 76 | 0 | require Venus; | |
| 77 | |||
| 78 | 0 | @_ = ("${self} cannot be used via the \"use\" declaration"); | |
| 79 | |||
| 80 | 0 | goto \&Venus::fault; | |
| 81 | } | ||
| 82 | |||
| 83 | sub meta { | ||
| 84 | 1 | ▶ | my ($self) = @_; |
|
Subroutine
meta: called CC=1 SCAR=0.0
Pod
documented
| |||
| 85 | |||
| 86 | 1 | return $self->META; | |
| 87 | } | ||
| 88 | |||
| 89 | sub unimport { | ||
| 90 | 0 | ▶ | my ($self, @args) = @_; |
|
Subroutine
unimport: not called CC=1 SCAR=6.9
| |||
| 91 | |||
| 92 | 0 | my $target = caller; | |
| 93 | |||
| 94 | 0 | return $self->UNIMPORT($target, @args); | |
| 95 | } | ||
| 96 | |||
| 97 | 96 | 1; | |
| 98 | |||
| 99 | |||
| 100 | |||
| 101 | =head1 NAME | ||
| 102 | |||
| 103 | Venus::Core::Role - Role Base Class | ||
| 104 | |||
| 105 | =cut | ||
| 106 | |||
| 107 | =head1 ABSTRACT | ||
| 108 | |||
| 109 | Role Base Class for Perl 5 | ||
| 110 | |||
| 111 | =cut | ||
| 112 | |||
| 113 | =head1 SYNOPSIS | ||
| 114 | |||
| 115 | package Person; | ||
| 116 | |||
| 117 | use base 'Venus::Core::Role'; | ||
| 118 | |||
| 119 | package User; | ||
| 120 | |||
| 121 | use base 'Venus::Core::Class'; | ||
| 122 | |||
| 123 | package main; | ||
| 124 | |||
| 125 | my $user = User->ROLE('Person')->new( | ||
| 126 | fname => 'Elliot', | ||
| 127 | lname => 'Alderson', | ||
| 128 | ); | ||
| 129 | |||
| 130 | # bless({fname => 'Elliot', lname => 'Alderson'}, 'User') | ||
| 131 | |||
| 132 | =cut | ||
| 133 | |||
| 134 | =head1 DESCRIPTION | ||
| 135 | |||
| 136 | This package provides a role base class with role building and object | ||
| 137 | construction lifecycle hooks. | ||
| 138 | |||
| 139 | =cut | ||
| 140 | |||
| 141 | =head1 INHERITS | ||
| 142 | |||
| 143 | This package inherits behaviors from: | ||
| 144 | |||
| 145 | L<Venus::Core> | ||
| 146 | |||
| 147 | =cut | ||
| 148 | |||
| 149 | =head1 METHODS | ||
| 150 | |||
| 151 | This package provides the following methods: | ||
| 152 | |||
| 153 | =cut | ||
| 154 | |||
| 155 | =head2 does | ||
| 156 | |||
| 157 | does(string $name) (boolean) | ||
| 158 | |||
| 159 | The does method returns true if the object is composed of the role provided. | ||
| 160 | |||
| 161 | I<Since C<1.00>> | ||
| 162 | |||
| 163 | =over 4 | ||
| 164 | |||
| 165 | =item does example 1 | ||
| 166 | |||
| 167 | package Employee; | ||
| 168 | |||
| 169 | use base 'Venus::Core::Role'; | ||
| 170 | |||
| 171 | Employee->ROLE('Person'); | ||
| 172 | |||
| 173 | package main; | ||
| 174 | |||
| 175 | my $user = User->ROLE('Employee')->new( | ||
| 176 | fname => 'Elliot', | ||
| 177 | lname => 'Alderson', | ||
| 178 | ); | ||
| 179 | |||
| 180 | my $does = Employee->does('Person'); | ||
| 181 | |||
| 182 | # 1 | ||
| 183 | |||
| 184 | =back | ||
| 185 | |||
| 186 | =cut | ||
| 187 | |||
| 188 | =head2 import | ||
| 189 | |||
| 190 | import(any @args) (any) | ||
| 191 | |||
| 192 | The import method throws a fatal exception whenever the L<perlfunc/use> | ||
| 193 | declaration is used with roles as they are meant to be consumed via the C<with> | ||
| 194 | or C<role> keyword functions. | ||
| 195 | |||
| 196 | I<Since C<2.91>> | ||
| 197 | |||
| 198 | =over 4 | ||
| 199 | |||
| 200 | =item import example 1 | ||
| 201 | |||
| 202 | package main; | ||
| 203 | |||
| 204 | use Person; | ||
| 205 | |||
| 206 | # Exception! (isa Venus::Fault) | ||
| 207 | |||
| 208 | =back | ||
| 209 | |||
| 210 | =cut | ||
| 211 | |||
| 212 | =head2 meta | ||
| 213 | |||
| 214 | meta() (Venus::Meta) | ||
| 215 | |||
| 216 | The meta method returns a L<Venus::Meta> objects which describes the package's | ||
| 217 | configuration. | ||
| 218 | |||
| 219 | I<Since C<1.00>> | ||
| 220 | |||
| 221 | =over 4 | ||
| 222 | |||
| 223 | =item meta example 1 | ||
| 224 | |||
| 225 | package main; | ||
| 226 | |||
| 227 | my $user = User->ROLE('Person')->new( | ||
| 228 | fname => 'Elliot', | ||
| 229 | lname => 'Alderson', | ||
| 230 | ); | ||
| 231 | |||
| 232 | my $meta = Person->meta; | ||
| 233 | |||
| 234 | # bless({...}, 'Venus::Meta') | ||
| 235 | |||
| 236 | =back | ||
| 237 | |||
| 238 | =cut | ||
| 239 | |||
| 240 | =head2 unimport | ||
| 241 | |||
| 242 | unimport(any @args) (any) | ||
| 243 | |||
| 244 | The unimport method invokes the C<UNIMPORT> lifecycle hook and is invoked | ||
| 245 | whenever the L<perlfunc/no> declaration is used. | ||
| 246 | |||
| 247 | I<Since C<2.91>> | ||
| 248 | |||
| 249 | =over 4 | ||
| 250 | |||
| 251 | =item unimport example 1 | ||
| 252 | |||
| 253 | package main; | ||
| 254 | |||
| 255 | no User; | ||
| 256 | |||
| 257 | # () | ||
| 258 | |||
| 259 | =back | ||
| 260 | |||
| 261 | =cut | ||
| 262 | |||
| 263 | =head1 AUTHORS | ||
| 264 | |||
| 265 | Awncorp, C<awncorp@cpan.org> | ||
| 266 | |||
| 267 | =cut | ||
| 268 | |||
| 269 | =head1 LICENSE | ||
| 270 | |||
| 271 | Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>. | ||
| 272 | |||
| 273 | This program is free software, you can redistribute it and/or modify it under | ||
| 274 | the terms of the Apache license version 2.0. | ||
| 275 | |||
| 276 | =cut | ||