| 1 | package Class::Implant; | ||||||||||
| 2 | # ABSTRACT: Manipulating mixin and inheritance out of packages | ||||||||||
| 3 | |||||||||||
| 4 | 4 | ▶ | use 5.008008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | no strict "refs"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | ▶ | use Class::Inspector; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 4 | our $VERSION = '0.01'; | |||||||||
| 11 | |||||||||||
| 12 | 4 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 4 | *{(caller)[0] . "::implant"} = \&implant; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 3 | ▶ | sub implant (@) { | ||||||||
|
Subroutine
implant: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||
| 17 | 3 | ▶ | my $option = ( ref($_[-1]) eq "HASH" ? pop(@_) : undef ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 3 | my @class = @_; | |||||||||
| 19 | |||||||||||
| 20 | 3 | my $target = caller; | |||||||||
| 21 | |||||||||||
| 22 | 3 | ▶ | if (defined($option)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 2 | ▶ | $target = $option->{into} if defined($option->{into}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 2 | ▶ | eval qq{ package $target; use base qw(@class); } if $option->{inherit}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 3 | for my $class (reverse @class) { | |||||||||
| 28 | 3 | for my $function (@{ _get_methods($class) }) { | |||||||||
| 29 | 6 | *{ $target . "::" . $function } = \&{ $class . "::" . $function }; | |||||||||
| 30 | } | ||||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 3 | ▶ | sub _get_methods { Class::Inspector->functions(shift) } | ||||||||
|
Subroutine
_get_methods: called CC=1 SCAR=0.0
| |||||||||||
| 36 | |||||||||||
| 37 | 4 | 1; | |||||||||
| 38 | |||||||||||
| 39 | |||||||||||
| 40 | __END__ | ||||||||||