| 1 | package assertions::compat; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | our $VERSION = '0.02'; | |||||||||
| 4 | |||||||||||
| 5 | 2 | require assertions; | |||||||||
| 6 | 2 | our @ISA = qw(assertions); | |||||||||
| 7 | |||||||||||
| 8 | sub _on () { 1 } | ||||||||||
| 9 | sub _off () { 0 } | ||||||||||
| 10 | |||||||||||
| 11 | 6 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=5 SCAR=16.2
| |||||||||||
| 12 | 6 | my $class = shift; | |||||||||
| 13 | 6 | ▶ | my $name = @_ ? shift : 'asserting'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | 6 | my $pkg = caller; | |||||||||
| 15 | 6 | ▶ | $name =~ /::/ or $name = "${pkg}::${name}"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 6 | ▶ | @_ = $pkg unless @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 6 | $class->SUPER::import(@_); | |||||||||
| 18 | 6 | my $enabled = assertions::enabled(); | |||||||||
| 19 | { | ||||||||||
| 20 | 2 | ▶ | no strict 'vars'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 2 | ▶ | no warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 6 | undef &{$name}; | |||||||||
| 23 | 6 | ▶ | *{$name} = $enabled ? \&_on : \&_off; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | } | ||||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 3 | ▶ | sub _compat_assertion_handler { | ||||||||
|
Subroutine
_compat_assertion_handler: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 3 | shift; shift; | |||||||||
| 29 | 3 | grep $_ ne 'assertion', @_ | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub _do_nothing_handler {} | ||||||||
|
Subroutine
_do_nothing_handler: not called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | # test if 'assertion' attribute is natively supported | ||||||||||
| 35 | 0 | ▶ | my $assertion_ok=eval q{ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
_my_asserting_test: not called CC=1 SCAR=0.1
| |||||||||||
| 36 | sub _my_asserting_test : assertion { 1 } | ||||||||||
| 37 | _my_asserting_test() | ||||||||||
| 38 | }; | ||||||||||
| 39 | |||||||||||
| 40 | 2 | ▶ | *MODIFY_CODE_ATTRIBUTES = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | defined($assertion_ok) | ||||||||||
| 42 | ? \&_do_nothing_handler | ||||||||||
| 43 | : \&_compat_assertion_handler; | ||||||||||
| 44 | |||||||||||
| 45 | 2 | ▶ | *supported = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | defined($assertion_ok) | ||||||||||
| 47 | ? \&_on | ||||||||||
| 48 | : \&_off; | ||||||||||
| 49 | |||||||||||
| 50 | 2 | ▶ | unless (defined $assertion_ok) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | package assertions; | ||||||||||
| 52 | 2 | require warnings::register; | |||||||||
| 53 | 2 | warnings::register->import; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | |||||||||||
| 57 | 2 | 1; | |||||||||
| 58 | |||||||||||
| 59 | __END__ | ||||||||||