assertions/compat.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 57.1% 8 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod n/a totaltotal 83.9% 47 / 56 CC 5 SCAR 10.4
CC
5
Cov
86%
import
5.0
BEGIN
1.0
_my_asserting_test
1.0
CRAP 2.8
« assertions/activate.pm ↑ Summary
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
BranchTrueFalseTotal
@_ ? : 6 0 6
14 6 my $pkg = caller;
15 6 ▶ $name =~ /::/ or $name = "${pkg}::${name}";
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /::/ or $name = "${pkg}::$name" 0 6 6
16 6 ▶ @_ = $pkg unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 6 6
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
BranchTrueFalseTotal
$enabled ? : 4 2 6
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
BranchTrueFalseTotal
defined $assertion_ok ? : 0 2 2
41 defined($assertion_ok)
42 ? \&_do_nothing_handler
43 : \&_compat_assertion_handler;
44  
45 2 ▶*supported =
Branch: 1 branch
BranchTrueFalseTotal
defined $assertion_ok ? : 0 2 2
46 defined($assertion_ok)
47 ? \&_on
48 : \&_off;
49  
50 2 ▶unless (defined $assertion_ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $assertion_ok) 2 0 2
51 package assertions;
52 2 require warnings::register;
53 2 warnings::register->import;
54 }
55  
56  
57 2 1;
58  
59 __END__
« assertions/activate.pm ↑ Summary