| 1 | package Sub::WrapInType::Attribute; | ||||||||||||||||||||
| 2 | 5 | ▶ | use v5.14.0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 5 | our $VERSION = "0.02"; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 5 | ▶ | use Attribute::Handlers; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 5 | ▶ | use B::Hooks::EndOfScope; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 5 | ▶ | use Sub::WrapInType (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 5 | ▶ | use Sub::Util (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 5 | ▶ | use attributes; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 5 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 5 | ▶ | my $DEFAULT_CHECK = !!($ENV{SUB_WRAPINTYPE_ATTRIBUTE_CHECK} // 1); | ||||||||||||||||||
|
Condition100%2/2
$ENV{"SUB_WRAPINTYPE_ATTRIBUTE_CHECK"} // 1
MC/DC100%1/1
$ENV{"SUB_WRAPINTYPE_ATTRIBUTE_CHECK"} // 1
$ENV{"SUB_WRAPINTYPE_ATTRIBUTE_CHECK"}
Truth table100%2/2
A
A= $ENV{"SUB_WRAPINTYPE_ATTRIBUTE_CHECK"}
| |||||||||||||||||||||
| 16 | 5 | my %CHECK; | |||||||||||||||||||
| 17 | my @INSTALL_ARGS; | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 5 | ▶ | sub import { | ||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 20 | 5 | my $class = shift; | |||||||||||||||||||
| 21 | 5 | my %args = @_; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 5 | ▶ | my $pkg = $args{pkg} ? $args{pkg} : scalar caller; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 5 | ▶ | $CHECK{$pkg} = !!$args{check} if exists $args{check}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | { | ||||||||||||||||||||
| 26 | # allow importing package to use attribute | ||||||||||||||||||||
| 27 | 5 | ▶ | no strict qw(refs); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | 5 | my $MODIFY_CODE_ATTRIBUTES = \&Attribute::Handlers::UNIVERSAL::MODIFY_CODE_ATTRIBUTES; | |||||||||||||||||||
| 29 | 5 | *{"${pkg}::MODIFY_CODE_ATTRIBUTES"} = $MODIFY_CODE_ATTRIBUTES; | |||||||||||||||||||
| 30 | 5 | *{"${pkg}::_ATTR_CODE_WrapSub"} = $class->can('WrapSub'); | |||||||||||||||||||
| 31 | 5 | *{"${pkg}::_ATTR_CODE_WrapMethod"} = $class->can('WrapMethod'); | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 5 | ▶ | on_scope_end { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 35 | 5 | ▶ | while (my $args = shift @INSTALL_ARGS) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 10 | $class->_install(@$args); | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | 5 | }; | |||||||||||||||||||
| 39 | 5 | return; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 6 | ▶ | sub WrapSub :ATTR(CODE,BEGIN) { | ||||||||||||||||||
|
Subroutine
WrapSub: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 43 | 6 | my ($pkg, @args) = @_; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | my $opts = { | ||||||||||||||||||||
| 46 | 6 | ▶ | check => $CHECK{$pkg} // $DEFAULT_CHECK, | ||||||||||||||||||
|
Condition66%2/3
$CHECK{$pkg} // $DEFAULT_CHECK
MC/DC0%0/2
$CHECK{$pkg} // $DEFAULT_CHECK
$CHECK{$pkg}
$DEFAULT_CHECK
Truth table66%2/3
A // B
A= $CHECK{$pkg}B= $DEFAULT_CHECK
| |||||||||||||||||||||
| 47 | skip_invocant => 0, | ||||||||||||||||||||
| 48 | }; | ||||||||||||||||||||
| 49 | 6 | push @INSTALL_ARGS => [$opts, $pkg, @args]; | |||||||||||||||||||
| 50 | 6 | return; | |||||||||||||||||||
| 51 | 5 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 4 | ▶ | sub WrapMethod :ATTR(CODE,BEGIN) { | ||||||||||||||||||
|
Subroutine
WrapMethod: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 54 | 4 | my ($pkg, @args) = @_; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | my $opts = { | ||||||||||||||||||||
| 57 | 4 | ▶ | check => $CHECK{$pkg} // $DEFAULT_CHECK, | ||||||||||||||||||
|
Condition66%2/3
$CHECK{$pkg} // $DEFAULT_CHECK
MC/DC0%0/2
$CHECK{$pkg} // $DEFAULT_CHECK
$CHECK{$pkg}
$DEFAULT_CHECK
Truth table66%2/3
A // B
A= $CHECK{$pkg}B= $DEFAULT_CHECK
| |||||||||||||||||||||
| 58 | skip_invocant => 1, | ||||||||||||||||||||
| 59 | }; | ||||||||||||||||||||
| 60 | 4 | push @INSTALL_ARGS => [$opts, $pkg, @args]; | |||||||||||||||||||
| 61 | 4 | return; | |||||||||||||||||||
| 62 | 5 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 10 | ▶ | sub _install { | ||||||||||||||||||
|
Subroutine
_install: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 65 | 10 | my $class = shift; | |||||||||||||||||||
| 66 | 10 | my ($options, $pkg, $symbol, $code, $attr, $data) = @_; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 10 | my $typed_code = Sub::WrapInType->new( | |||||||||||||||||||
| 69 | params => $data->[0], | ||||||||||||||||||||
| 70 | isa => $data->[1], | ||||||||||||||||||||
| 71 | code => $code, | ||||||||||||||||||||
| 72 | options => $options, | ||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 10 | ▶ | if (my @attr = attributes::get($code)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 5 | ▶ | no warnings qw(misc); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 77 | 1 | attributes->import($pkg, $typed_code, @attr); | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 10 | my $prototype = Sub::Util::prototype($code); | |||||||||||||||||||
| 81 | 10 | Sub::Util::set_prototype($prototype, $typed_code); | |||||||||||||||||||
| 82 | 10 | Sub::Util::set_subname(Sub::Util::subname($code), $typed_code); | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | { | ||||||||||||||||||||
| 85 | 5 | ▶ | no strict qw(refs); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 86 | 5 | ▶ | no warnings qw(redefine); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 87 | 10 | *$symbol = $typed_code; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | 10 | return; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 5 | 1; | |||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||