| 1 | package Venus::Kind; | ||||||||||||||||||||||||||||
| 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 | ▶ | use Venus::Class 'with'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 96 | with 'Venus::Role::Boxable'; | |||||||||||||||||||||||||||
| 11 | 96 | with 'Venus::Role::Tryable'; | |||||||||||||||||||||||||||
| 12 | 96 | with 'Venus::Role::Catchable'; | |||||||||||||||||||||||||||
| 13 | 96 | with 'Venus::Role::Comparable'; | |||||||||||||||||||||||||||
| 14 | 96 | with 'Venus::Role::Deferrable'; | |||||||||||||||||||||||||||
| 15 | 96 | with 'Venus::Role::Dumpable'; | |||||||||||||||||||||||||||
| 16 | 96 | with 'Venus::Role::Digestable'; | |||||||||||||||||||||||||||
| 17 | 96 | with 'Venus::Role::Doable'; | |||||||||||||||||||||||||||
| 18 | 96 | with 'Venus::Role::Matchable'; | |||||||||||||||||||||||||||
| 19 | 96 | with 'Venus::Role::Printable'; | |||||||||||||||||||||||||||
| 20 | 96 | with 'Venus::Role::Reflectable'; | |||||||||||||||||||||||||||
| 21 | 96 | with 'Venus::Role::Testable'; | |||||||||||||||||||||||||||
| 22 | 96 | with 'Venus::Role::Throwable'; | |||||||||||||||||||||||||||
| 23 | 96 | with 'Venus::Role::Assertable'; | |||||||||||||||||||||||||||
| 24 | 96 | with 'Venus::Role::Serializable'; | |||||||||||||||||||||||||||
| 25 | 96 | with 'Venus::Role::Mockable'; | |||||||||||||||||||||||||||
| 26 | 96 | with 'Venus::Role::Patchable'; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # METHODS | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub checksum { | ||||||||||||||||||||||||||||
| 31 | 346 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
checksum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 346 | return $self->digest('md5', 'stringified'); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub comparer { | ||||||||||||||||||||||||||||
| 37 | 797 | ▶ | my ($self, $operation) = @_; | ||||||||||||||||||||||||||
|
Subroutine
comparer: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 797 | ▶ | if (lc($operation) eq 'eq') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 516 | return 'checksum'; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 281 | ▶ | if (lc($operation) eq 'gt') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 155 | return 'numified'; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 126 | ▶ | if (lc($operation) eq 'lt') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 126 | return 'numified'; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | else { | ||||||||||||||||||||||||||||
| 49 | 0 | return 'stringified'; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub numified { | ||||||||||||||||||||||||||||
| 54 | 663 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
numified: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 663 | return CORE::length($self->stringified); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub renew { | ||||||||||||||||||||||||||||
| 60 | 7 | ▶ | my ($self, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
renew: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 7 | my $data = $self->ARGS(@args); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 7 | for my $attr (@{$self->meta->attrs}) { | |||||||||||||||||||||||||||
| 65 | 8 | ▶ | $data->{$attr} = $self->$attr if exists $self->{$attr} && !exists $data->{$attr}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $self->{$attr} and not exists $data->{$attr}
MC/DC100%2/2
exists $self->{$attr} and not exists $data->{$attr}
exists $self->{$attr}
not exists $data->{$attr}
Truth table100%3/3
A and not(B)
A= exists $self->{$attr}B= not exists $data->{$attr}
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 7 | return $self->class->new($data); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub safe { | ||||||||||||||||||||||||||||
| 72 | 4 | ▶ | my ($self, $method, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
safe: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 4 | my $result = $self->trap($method, @args); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 4 | ▶ | return(wantarray ? (@$result) : $result->[0]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | sub self { | ||||||||||||||||||||||||||||
| 80 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
self: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | return $self; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub stringified { | ||||||||||||||||||||||||||||
| 86 | 1341 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
stringified: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1341 | ▶ | return $self->dump($self->can('value') ? 'value' : ()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | sub trap { | ||||||||||||||||||||||||||||
| 92 | 10 | ▶ | my ($self, $method, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
trap: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 96 | ▶ | no strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 95 | 96 | ▶ | no warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 10 | my $result = [[],[],[]]; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 10 | ▶ | return(wantarray ? (@$result) : $result->[0]) if !$method; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 10 | local ($!, $?, $@, $^E); | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | local $SIG{__DIE__} = sub{ | ||||||||||||||||||||||||||||
| 104 | 5 | ▶ | push @{$result->[2]}, @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 105 | 10 | }; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | local $SIG{__WARN__} = sub{ | ||||||||||||||||||||||||||||
| 108 | 3 | ▶ | push @{$result->[1]}, @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 109 | 10 | }; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 10 | push @{$result->[0]}, eval { | |||||||||||||||||||||||||||
| 112 | 10 | local $_ = $self; | |||||||||||||||||||||||||||
| 113 | 10 | $self->$method(@args); | |||||||||||||||||||||||||||
| 114 | }; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 10 | ▶ | return(wantarray ? (@$result) : $result->[0]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 96 | 1; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head1 NAME | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | Venus::Kind - Kind Base Class | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =cut | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =head1 ABSTRACT | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | Kind Base Class for Perl 5 | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =cut | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | package Example; | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | use Venus::Class; | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | base 'Venus::Kind'; | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | package main; | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | my $example = Example->new; | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # bless({}, "Example") | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | This package provides identity and methods common across all L<Venus> classes. | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =cut | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head1 INTEGRATES | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | This package integrates behaviors from: | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | L<Venus::Role::Assertable> | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | L<Venus::Role::Boxable> | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | L<Venus::Role::Catchable> | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | L<Venus::Role::Comparable> | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | L<Venus::Role::Deferrable> | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | L<Venus::Role::Digestable> | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | L<Venus::Role::Doable> | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | L<Venus::Role::Dumpable> | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | L<Venus::Role::Matchable> | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | L<Venus::Role::Mockable> | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | L<Venus::Role::Patchable> | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | L<Venus::Role::Printable> | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | L<Venus::Role::Reflectable> | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | L<Venus::Role::Serializable> | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | L<Venus::Role::Testable> | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | L<Venus::Role::Throwable> | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | L<Venus::Role::Tryable> | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =cut | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =head1 METHODS | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | This package provides the following methods: | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =cut | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =head2 assertion | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | assertion() (Venus::Assert) | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | The assertion method returns a L<Venus::Assert> object based on the invocant. | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | I<Since C<1.23>> | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =over 4 | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =item assertion example 1 | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | # given: synopsis | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | package main; | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | my $assertion = $example->assertion; | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | # bless({name => "Example"}, "Venus::Assert") | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =back | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | =cut | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =head2 checksum | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | checksum() (string) | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | The checksum method returns an md5 hash string representing the stringified | ||||||||||||||||||||||||||||
| 232 | object value (or the object itself). | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | I<Since C<0.08>> | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =over 4 | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | =item checksum example 1 | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | # given: synopsis; | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | my $checksum = $example->checksum; | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | # "859a86eed4b2d97eb7b830b02f06de32" | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | =back | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | =over 4 | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | =item checksum example 2 | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | package Checksum::Example; | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | use Venus::Class; | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | base 'Venus::Kind'; | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | attr 'value'; | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | package main; | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | my $example = Checksum::Example->new(value => 'example'); | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | my $checksum = $example->checksum; | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | # "1a79a4d60de6718e8e5b326e338ae533" | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | =back | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | =cut | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | =head2 numified | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | numified() (number) | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | The numified method returns the numerical representation of the object which is | ||||||||||||||||||||||||||||
| 277 | typically the length (or character count) of the stringified object. | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | I<Since C<0.08>> | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | =over 4 | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | =item numified example 1 | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | # given: synopsis; | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | my $numified = $example->numified; | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | # 22 | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | =back | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | =over 4 | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | =item numified example 2 | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | package Numified::Example; | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | use Venus::Class; | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | base 'Venus::Kind'; | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | attr 'value'; | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | package main; | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | my $example = Numified::Example->new(value => 'example'); | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | my $numified = $example->numified; | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | # 7 | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | =back | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | =cut | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | =head2 renew | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | renew(any @args) (object) | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | The renew method returns a new instance of the invocant by instantiating the | ||||||||||||||||||||||||||||
| 322 | underlying class passing all recognized class attributes to the constructor. | ||||||||||||||||||||||||||||
| 323 | B<Note:> This method is not analogous to C<clone>, i.e. attributes which are | ||||||||||||||||||||||||||||
| 324 | references will be passed to the new object as references. | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | I<Since C<1.23>> | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | =over 4 | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | =item renew example 1 | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | # given: synopsis | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | package main; | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | my $renew = $example->renew; | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | # bless({}, "Example") | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | =back | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | =over 4 | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | =item renew example 2 | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | package Example; | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | use Venus::Class; | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | base 'Venus::Kind'; | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | attr 'values'; | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | package main; | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | my $example = Example->new(values => [1,2]); | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | my $renew = $example->renew; | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | # bless({values => [1,2]}, "Example") | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | =back | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | =over 4 | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | =item renew example 3 | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | package Example; | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | use Venus::Class; | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | base 'Venus::Kind'; | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | attr 'keys'; | ||||||||||||||||||||||||||||
| 375 | attr 'values'; | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | package main; | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | my $example = Example->new(values => [1,2]); | ||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | my $renew = $example->renew(keys => ['a','b']); | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | # bless({keys => ["a","b"], values => [1,2]}, "Example") | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | =back | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | =cut | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | =head2 safe | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | safe(string | coderef $code, any @args) (any) | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | The safe method dispatches the method call or executes the callback and returns | ||||||||||||||||||||||||||||
| 394 | the result, supressing warnings and exceptions. If an exception is thrown this | ||||||||||||||||||||||||||||
| 395 | method will return C<undef>. This method supports dispatching, i.e. providing a | ||||||||||||||||||||||||||||
| 396 | method name and arguments whose return value will be acted on by this method. | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | I<Since C<0.08>> | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | =over 4 | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | =item safe example 1 | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | # given: synopsis; | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | my $safe = $example->safe('class'); | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | # "Example" | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | =back | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | =over 4 | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | =item safe example 2 | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | # given: synopsis; | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | my $safe = $example->safe(sub { | ||||||||||||||||||||||||||||
| 419 | ${_}->class / 2 | ||||||||||||||||||||||||||||
| 420 | }); | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | # '0' | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | =back | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | =over 4 | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | =item safe example 3 | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | # given: synopsis; | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | my $safe = $example->safe(sub { | ||||||||||||||||||||||||||||
| 433 | die; | ||||||||||||||||||||||||||||
| 434 | }); | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | # undef | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | =back | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | =cut | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | =head2 self | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | self() (any) | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | The self method returns the invocant. | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | I<Since C<1.23>> | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | =over 4 | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | =item self example 1 | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | # given: synopsis | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | package main; | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | my $self = $example->self; | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | # bless({}, "Example") | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | =back | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | =cut | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | =head2 stringified | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | stringified() (string) | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | The stringified method returns the object, stringified (i.e. a dump of the | ||||||||||||||||||||||||||||
| 471 | object's value). | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | I<Since C<0.08>> | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | =over 4 | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | =item stringified example 1 | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | # given: synopsis; | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | my $stringified = $example->stringified; | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | # bless({}, 'Example') | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | =back | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | =over 4 | ||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | =item stringified example 2 | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | package Stringified::Example; | ||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | use Venus::Class; | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | base 'Venus::Kind'; | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | attr 'value'; | ||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | package main; | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | my $example = Stringified::Example->new(value => 'example'); | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | my $stringified = $example->stringified; | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | # "example" | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | =back | ||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | =cut | ||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | =head2 trap | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | trap(string | coderef $code, any @args) (tuple[arrayref, arrayref, arrayref]) | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | The trap method dispatches the method call or executes the callback and returns | ||||||||||||||||||||||||||||
| 519 | a tuple (i.e. a 3-element arrayref) with the results, warnings, and exceptions | ||||||||||||||||||||||||||||
| 520 | from the code execution. If an exception is thrown, the results (i.e. the | ||||||||||||||||||||||||||||
| 521 | 1st-element) will be an empty arrayref. This method supports dispatching, i.e. | ||||||||||||||||||||||||||||
| 522 | providing a method name and arguments whose return value will be acted on by | ||||||||||||||||||||||||||||
| 523 | this method. | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | I<Since C<0.08>> | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | =over 4 | ||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | =item trap example 1 | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | # given: synopsis; | ||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | my $result = $example->trap('class'); | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | # ["Example"] | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | =back | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | =over 4 | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | =item trap example 2 | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | # given: synopsis; | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | my ($results, $warnings, $errors) = $example->trap('class'); | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | # (["Example"], [], []) | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | =back | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | =over 4 | ||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | =item trap example 3 | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | # given: synopsis; | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | my $trap = $example->trap(sub { | ||||||||||||||||||||||||||||
| 558 | ${_}->class / 2 | ||||||||||||||||||||||||||||
| 559 | }); | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | # ["0"] | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | =back | ||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | =over 4 | ||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | =item trap example 4 | ||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | # given: synopsis; | ||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | my ($results, $warnings, $errors) = $example->trap(sub { | ||||||||||||||||||||||||||||
| 572 | ${_}->class / 2 | ||||||||||||||||||||||||||||
| 573 | }); | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | # (["0"], ["Argument ... isn't numeric in division ..."], []) | ||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | =back | ||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | =over 4 | ||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | =item trap example 5 | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | # given: synopsis; | ||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | my $trap = $example->trap(sub { | ||||||||||||||||||||||||||||
| 586 | die; | ||||||||||||||||||||||||||||
| 587 | }); | ||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | # [] | ||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | =back | ||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | =over 4 | ||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | =item trap example 6 | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | # given: synopsis; | ||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | my ($results, $warnings, $errors) = $example->trap(sub { | ||||||||||||||||||||||||||||
| 600 | die; | ||||||||||||||||||||||||||||
| 601 | }); | ||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | # ([], [], ["Died..."]) | ||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | =back | ||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||
| 607 | =cut | ||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||
| 609 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | Awncorp, C<awncorp@cpan.org> | ||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | =cut | ||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||
| 617 | Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>. | ||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | This program is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 620 | the terms of the Apache license version 2.0. | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | =cut | ||||||||||||||||||||||||||||