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