| 1 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | |||
| 4 | package Util::H2O::More; | ||
| 5 | 2 | ▶ | use parent q/Exporter/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 2 | our $VERSION = q{0.0.2}; | |
| 8 | |||
| 9 | 2 | our @EXPORT_OK = (qw/baptise baptise_deeply/); | |
| 10 | |||
| 11 | 2 | ▶ | use Util::H2O qw/h2o/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 2 | ▶ | use feature 'state'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | # maintains basically a count to create non-colliding | ||
| 15 | # unique $pkg names (basically what Util::H2O::h2o does | ||
| 16 | # if $pkg is not specified using -class | ||
| 17 | |||
| 18 | # monatomically increasing uuid | ||
| 19 | sub _uuid { | ||
| 20 | 5 | ▶ | state $uuid = 0; |
|
Subroutine
_uuid: called CC=1 SCAR=0.0
| |||
| 21 | 5 | return ++$uuid; | |
| 22 | } | ||
| 23 | |||
| 24 | # non-recursive option | ||
| 25 | sub baptise ($$@) { | ||
| 26 | 4 | ▶ | my ( $ref, $pkg, @default_accessors ) = @_; |
|
Subroutine
baptise: called CC=1 SCAR=0.0
Pod
documented
| |||
| 27 | |||
| 28 | 4 | my $self; | |
| 29 | 4 | my $real_pkg = sprintf qq{%s::_%s}, $pkg, _uuid; | |
| 30 | |||
| 31 | # uses -isa to inherit from $pkg; -class to bless with a package name | ||
| 32 | # derived from $pkg | ||
| 33 | 4 | $self = h2o -isa => $pkg, -class => $real_pkg, $ref, @default_accessors; | |
| 34 | |||
| 35 | 4 | return $self; | |
| 36 | } | ||
| 37 | |||
| 38 | # recursive option | ||
| 39 | sub baptise_deeply ($$@) { | ||
| 40 | 1 | ▶ | my ( $ref, $pkg, @default_accessors ) = @_; |
|
Subroutine
baptise_deeply: called CC=1 SCAR=0.0
Pod
documented
| |||
| 41 | |||
| 42 | 1 | my $self; | |
| 43 | 1 | my $real_pkg = sprintf qq{%s::_%s}, $pkg, _uuid; | |
| 44 | |||
| 45 | # uses -isa to inherit from $pkg; -class to bless with a package name | ||
| 46 | # derived from $pkg | ||
| 47 | 1 | $self = h2o -recurse, -isa => $pkg, -class => $real_pkg, $ref, @default_accessors; | |
| 48 | |||
| 49 | 1 | return $self; | |
| 50 | } | ||
| 51 | |||
| 52 | 2 | 1; | |
| 53 | |||
| 54 | __END__ | ||