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