blib/lib/Devel/Assert.pm

filter: Statementstmt 100% 41 / 41 Branchbran 90.0% 9 / 10 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 4 / 4 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 2 totaltotal 94.3% 67 / 71 CC 9 SCAR 13.9
CC
9
Cov
98%
import
6.0
assert_fail
4.0
BEGIN
1.0
CRAP 4.0
↑ Summary Assert.xs »
1 package Devel::Assert;
2 7 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 7 our $VERSION = '1.06';
6  
7 7 our $__ASSERT_GLOBAL = 0;
8  
9 7 require XSLoader;
10 7 XSLoader::load('Devel::Assert', $VERSION);
11  
12 13 ▶sub import {
Subroutine import: called CC=6 SCAR=17.9
13 13 my ($class, $arg) = @_;
14 13 my $caller = caller;
15  
16 13 ▶ $__ASSERT_GLOBAL = 1 if $arg eq 'global';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "global" 3 10 13
17  
18 13 ▶ my $ref = $arg eq 'off' || !$__ASSERT_GLOBAL && $arg ne 'on' ? \&assert_off : \&assert_on;
Branch: 1 branch
BranchTrueFalseTotal
$arg eq 'off' || !$Devel::Assert::__ASSERT_GLOBAL && $arg ne 'on' ? : 3 10 13
Condition100%6/6
$arg eq "off" or not $Devel::Assert::__ASSERT_GLOBAL and $arg ne "on"
l!l&&r!l&&!r
1210
not $Devel::Assert::__ASSERT_GLOBAL and $arg ne "on"
!ll&&!rl&&r
732
MC/DC100%3/3
$arg eq "off" or not $Devel::Assert::__ASSERT_GLOBAL and $arg ne "on"
$arg eq "off" not $Devel::Assert::__ASSERT_GLOBAL $arg ne "on"
Truth table100%4/4
A or not(B) and C
A= $arg eq "off"B= not $Devel::Assert::__ASSERT_GLOBALC= $arg ne "on"
ABCresult
1XX1
0111
00X0
0100
19 {
20 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 13 ▶ *{"${caller}::assert"} = $ref if !defined *{"${caller}::assert"}{CODE};
Branch: 1 branch
BranchTrueFalseTotal
if not defined *{"${caller}::assert";}{"CODE"} 12 1 13
22 }
23 }
24  
25 0 ▶sub assert_off {}
Subroutine assert_off: not called CC=1 SCAR=0.0
Pod undocumented
26  
27 12 ▶sub assert_fail {
Subroutine assert_fail: called CC=4 SCAR=13.9
Pod undocumented
28 12 my ($op, $cop, $upcv) = @_;
29  
30 # idea taken from Zefram's Debug::Show
31 # this code knows too much about B::Deparser internals
32  
33 12 ▶ unless (state $init_done++) {
Branch: 1 branch
BranchTrueFalseTotal
unless (state $init_done++) 5 7 12
34 5 require B;
35 5 require B::Deparse;
36  
37 5 require Carp;
38 5 $Carp::Internal{'Devel::Assert'}++;
39 }
40  
41 12 my $deparser = B::Deparse->new;
42 12 $deparser->{curcop} = $cop;
43 12 $deparser->{curcv} = $upcv;
44  
45 12 my $deparsed;
46 {
47 12 local $@;
48 12 local $SIG{__DIE__};
49  
50 12 ▶ $deparsed = eval {
Condition100%2/2
eval { do { $deparser->indent($deparser->deparse($op->sibling, 50)) } } || '0'
l!l
39
MC/DC100%1/1
eval { do { $deparser->indent($deparser->deparse($op->sibling, 50)) } } || '0'
eval { do { $deparser->indent($deparser->deparse($op->sibling, 50)) } }
Truth table100%2/2
A
A= eval { do { $deparser->indent($deparser->deparse($op->sibling, 50)) } }
Aresult
11
00
51 12 $deparser->indent($deparser->deparse($op->sibling, 50));
52 } || "0";
53 12 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 12 12
54  
55 12 $deparsed =~ s/\n[\t ]*/ /g;
56 12 $deparsed =~ s/^[(]//;
57 12 $deparsed =~ s/[)]$//;
58 }
59  
60 12 Carp::confess("Assertion '$deparsed' failed");
61 }
62  
63 7 1;
64  
↑ Summary Assert.xs »