| 1 | package Evo::Attr; | ||||||||||||
| 2 | 67 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 67 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 67 | ▶ | use Carp 'croak'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 67 | ▶ | use Evo::Internal::Util; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 67 | ▶ | use feature 'signatures'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 67 | ▶ | no warnings 'experimental::signatures'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 67 | my $MCO = \&invoke_handlers; | |||||||||||
| 10 | |||||||||||||
| 11 | ▶ | sub patch_package ($me, $pkg) { | |||||||||||
|
Subroutine
patch_package: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 12 | 258 | Evo::Internal::Util::monkey_patch $pkg, MODIFY_CODE_ATTRIBUTES => $MCO; | |||||||||||
| 13 | } | ||||||||||||
| 14 | |||||||||||||
| 15 | 67 | our %HANDLERS; | |||||||||||
| 16 | |||||||||||||
| 17 | ▶ | %HANDLERS = ( | |||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 18 | Attr => { | ||||||||||||
| 19 | provider => __PACKAGE__, | ||||||||||||
| 20 | handler => sub ($provider, $handler, $name) { | ||||||||||||
| 21 | 0 | register_attribute($provider, $name, $handler); | |||||||||||
| 22 | } | ||||||||||||
| 23 | } | ||||||||||||
| 24 | 67 | ); | |||||||||||
| 25 | |||||||||||||
| 26 | # $provider is a key, just for error message | ||||||||||||
| 27 | ▶ | sub register_attribute ($provider, $name, $handler) { | |||||||||||
|
Subroutine
register_attribute: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 28 | 0 | ▶ | croak "$name was already taken by $HANDLERS{$name}{provider}" if $HANDLERS{$name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 0 | $HANDLERS{$name} = {provider => $provider, handler => $handler}; | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | ▶ | sub invoke_handlers ($dest, $code, @attrs) { | |||||||||||
|
Subroutine
invoke_handlers: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 33 | 0 | my (undef, $subname) = Evo::Internal::Util::code2names($code); | |||||||||||
| 34 | 0 | my @remaining; | |||||||||||
| 35 | 0 | foreach my $attr_raw (@attrs) { | |||||||||||
| 36 | 0 | my ($attr, @args) = parse_attr($attr_raw); | |||||||||||
| 37 | |||||||||||||
| 38 | 0 | ▶ | if (my $slot = $HANDLERS{$attr}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | 0 | $slot->{handler}->($dest, $code, $subname, @args); | |||||||||||
| 40 | } | ||||||||||||
| 41 | 0 | else { push @remaining, $attr_raw } | |||||||||||
| 42 | } | ||||||||||||
| 43 | 0 | @remaining; | |||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | ▶ | sub parse_attr ($attr) { | |||||||||||
|
Subroutine
parse_attr: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 47 | 0 | $attr =~ /(\w+) ( \( \s* ([\w\,\s]+) \s* \) )?/x; | |||||||||||
| 48 | 0 | ▶ | return ($1, split /\,\s?/, $3 // ''); | ||||||||||
|
Condition0%0/2
$3 // ""
MC/DC0%0/1
$3 // ""
$3
Truth table0%0/2
A
A= $3
| |||||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | 67 | 1; | |||||||||||
| 52 | |||||||||||||
| 53 | __END__ | ||||||||||||