| 1 | package Venus::Core::Role; | ||
| 2 | |||
| 3 | 120 | ▶ | use 5.018; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 120 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 120 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 120 | ▶ | no warnings 'once'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 120 | ▶ | use base 'Venus::Core'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | # IMPORTS | ||
| 13 | |||
| 14 | 120 | ▶ | use Venus::Hook; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | |||
| 16 | # HOOKS | ||
| 17 | |||
| 18 | { | ||
| 19 | 120 | ▶ | no warnings 'once'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | |||
| 21 | 120 | *does = *Venus::Hook::DOES; | |
| 22 | |||
| 23 | 120 | *meta = *Venus::Hook::META; | |
| 24 | |||
| 25 | 120 | *BUILD = *Venus::Hook::BUILD_FOR_ROLE; | |
| 26 | |||
| 27 | 120 | *DESTROY = *Venus::Hook::DESTROY_FOR_ROLE; | |
| 28 | |||
| 29 | 120 | *EXPORT = *Venus::Hook::EXPORT_FOR_ROLE; | |
| 30 | |||
| 31 | 120 | *IMPORT = *Venus::Hook::IMPORT_FOR_ROLE; | |
| 32 | } | ||
| 33 | |||
| 34 | # METHODS | ||
| 35 | |||
| 36 | 0 | ▶ | sub import { |
|
Subroutine
import: not called CC=1 SCAR=6.9
| |||
| 37 | 0 | my ($self) = @_; | |
| 38 | |||
| 39 | 0 | require Venus; | |
| 40 | |||
| 41 | 0 | @_ = ("${self} cannot be used via the \"use\" declaration"); | |
| 42 | |||
| 43 | 0 | goto \&Venus::fault; | |
| 44 | } | ||
| 45 | |||
| 46 | 0 | ▶ | sub unimport { |
|
Subroutine
unimport: not called CC=1 SCAR=6.9
| |||
| 47 | 0 | my ($self, @args) = @_; | |
| 48 | |||
| 49 | 0 | my $target = caller; | |
| 50 | |||
| 51 | 0 | return $self->UNIMPORT($target, @args); | |
| 52 | } | ||
| 53 | |||
| 54 | 120 | 1; | |
| 55 | |||
| 56 | |||
| 57 | |||
| 58 | =head1 NAME | ||
| 59 | |||
| 60 | Venus::Core::Role - Role Base Class | ||
| 61 | |||
| 62 | =cut | ||
| 63 | |||
| 64 | =head1 ABSTRACT | ||
| 65 | |||
| 66 | Role Base Class for Perl 5 | ||
| 67 | |||
| 68 | =cut | ||
| 69 | |||
| 70 | =head1 SYNOPSIS | ||
| 71 | |||
| 72 | package Person; | ||
| 73 | |||
| 74 | use base 'Venus::Core::Role'; | ||
| 75 | |||
| 76 | package User; | ||
| 77 | |||
| 78 | use base 'Venus::Core::Class'; | ||
| 79 | |||
| 80 | package main; | ||
| 81 | |||
| 82 | my $user = User->ROLE('Person')->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 role base class with role building and object | ||
| 94 | construction lifecycle hooks. | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | =head1 INHERITS | ||
| 99 | |||
| 100 | This package inherits behaviors from: | ||
| 101 | |||
| 102 | L<Venus::Core> | ||
| 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(string $name) (boolean) | ||
| 115 | |||
| 116 | The does method returns true if the object is composed of the role provided. | ||
| 117 | |||
| 118 | I<Since C<1.00>> | ||
| 119 | |||
| 120 | =over 4 | ||
| 121 | |||
| 122 | =item does example 1 | ||
| 123 | |||
| 124 | package Employee; | ||
| 125 | |||
| 126 | use base 'Venus::Core::Role'; | ||
| 127 | |||
| 128 | Employee->ROLE('Person'); | ||
| 129 | |||
| 130 | package main; | ||
| 131 | |||
| 132 | my $user = User->ROLE('Employee')->new( | ||
| 133 | fname => 'Elliot', | ||
| 134 | lname => 'Alderson', | ||
| 135 | ); | ||
| 136 | |||
| 137 | my $does = Employee->does('Person'); | ||
| 138 | |||
| 139 | # 1 | ||
| 140 | |||
| 141 | =back | ||
| 142 | |||
| 143 | =cut | ||
| 144 | |||
| 145 | =head2 import | ||
| 146 | |||
| 147 | import(any @args) (any) | ||
| 148 | |||
| 149 | The import method throws a fatal exception whenever the L<perlfunc/use> | ||
| 150 | declaration is used with roles as they are meant to be consumed via the C<with> | ||
| 151 | or C<role> keyword functions. | ||
| 152 | |||
| 153 | I<Since C<2.91>> | ||
| 154 | |||
| 155 | =over 4 | ||
| 156 | |||
| 157 | =item import example 1 | ||
| 158 | |||
| 159 | package main; | ||
| 160 | |||
| 161 | use Person; | ||
| 162 | |||
| 163 | # Exception! (isa Venus::Fault) | ||
| 164 | |||
| 165 | =back | ||
| 166 | |||
| 167 | =cut | ||
| 168 | |||
| 169 | =head2 meta | ||
| 170 | |||
| 171 | meta() (Venus::Meta) | ||
| 172 | |||
| 173 | The meta method returns a L<Venus::Meta> objects which describes the package's | ||
| 174 | configuration. | ||
| 175 | |||
| 176 | I<Since C<1.00>> | ||
| 177 | |||
| 178 | =over 4 | ||
| 179 | |||
| 180 | =item meta example 1 | ||
| 181 | |||
| 182 | package main; | ||
| 183 | |||
| 184 | my $user = User->ROLE('Person')->new( | ||
| 185 | fname => 'Elliot', | ||
| 186 | lname => 'Alderson', | ||
| 187 | ); | ||
| 188 | |||
| 189 | my $meta = Person->meta; | ||
| 190 | |||
| 191 | # bless({...}, 'Venus::Meta') | ||
| 192 | |||
| 193 | =back | ||
| 194 | |||
| 195 | =cut | ||
| 196 | |||
| 197 | =head2 unimport | ||
| 198 | |||
| 199 | unimport(any @args) (any) | ||
| 200 | |||
| 201 | The unimport method invokes the C<UNIMPORT> lifecycle hook and is invoked | ||
| 202 | whenever the L<perlfunc/no> declaration is used. | ||
| 203 | |||
| 204 | I<Since C<2.91>> | ||
| 205 | |||
| 206 | =over 4 | ||
| 207 | |||
| 208 | =item unimport example 1 | ||
| 209 | |||
| 210 | package main; | ||
| 211 | |||
| 212 | no User; | ||
| 213 | |||
| 214 | # () | ||
| 215 | |||
| 216 | =back | ||
| 217 | |||
| 218 | =cut | ||
| 219 | |||
| 220 | =head1 AUTHORS | ||
| 221 | |||
| 222 | Awncorp, C<awncorp@cpan.org> | ||
| 223 | |||
| 224 | =cut | ||
| 225 | |||
| 226 | =head1 LICENSE | ||
| 227 | |||
| 228 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||
| 229 | |||
| 230 | This program is free software, you can redistribute it and/or modify it under | ||
| 231 | the terms of the Apache license version 2.0. | ||
| 232 | |||
| 233 | =cut | ||