blib/lib/dan.pm

filter: Statementstmt 44.7% 34 / 76 Branchbran 29.1% 7 / 24 Conditioncond 31.8% 7 / 22 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 42.8% 6 / 14 Podpod 16.6% 1 / 6 totaltotal 37.2% 57 / 153 CC 21 SCAR 26.4
CC
21
Cov
39%
run
42.0
cat_decode
20.0
unimport
12.0
CRAP 14.0
↑ Summary
1 package dan;
2  
3 7 ▶use 5.009005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use Encode qw(find_encoding);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 our $VERSION = '0.551.2';
10  
11 7 our $SINGLETON = bless { code => {} }, __PACKAGE__;
12  
13 0 ▶sub croak {
Subroutine croak: not called CC=1 SCAR=6.9
Pod undocumented
14 0 require Carp;
15 0 Carp::croak(__PACKAGE__ . ": @_");
16 }
17  
18 7 ▶my $LATIN1 = find_encoding('iso-8859-1')
Branch: 1 branch
BranchTrueFalseTotal
my $LATIN1 = &find_encoding("iso-8859-1") or croak("Can't load latin-1") 7 0 7
19 or croak("Can't load latin-1");
20  
21 7 my $DEFAULT_ENCODING;
22 my $DEFAULT_UTF8HINTBITS;
23 7 my $utf8_hint_bits = 0x00800000;
24 7 my $is_DanThe;
25  
26 7 ▶sub import {
Subroutine import: called CC=8 SCAR=21.8
27 7 my($class, %opts) = @_;
28  
29 7 ▶ if (exists $opts{the} && !$is_DanThe) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"the"} and not $is_DanThe) 1 6 7
Condition66%2/3
exists $opts{"the"} and not $is_DanThe
!ll&&!rl&&r
601
MC/DC50%1/2
exists $opts{"the"} and not $is_DanThe
exists $opts{"the"} not $is_DanThe
Truth table66%2/3
A and not(B)
A= exists $opts{"the"}B= not $is_DanThe
ABresult
0X0
100
111
30 1 ▶ eval "package the; sub Dan { shift; return wantarray ? \@_ : \$_[0] } 1;";
Subroutine Dan: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
31 1 $is_DanThe++;
32 1 return;
33 }
34  
35 6 ▶ if (ref($opts{cat_decode} || '') eq 'CODE' && ! exists $opts{decode}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($opts{"cat_decode"} || "") eq "CODE" and not exists $opts{"decode"}) 1 5 6
Condition80%4/5
ref($opts{"cat_decode"} || "") eq "CODE" and not exists $opts{"decode"}
!ll&&!rl&&r
501
$opts{'cat_decode'} || ''
l!l
15
MC/DC50%1/2
ref($opts{"cat_decode"} || "") eq "CODE" and not exists $opts{"decode"}
$opts{'cat_decode'} not exists $opts{"decode"}
Truth table66%2/3
A and not(B)
A= $opts{'cat_decode'}B= not exists $opts{"decode"}
ABresult
0X0
100
111
36 0 ▶ $opts{decode} = sub { shift };
Subroutine __ANON__: not called CC=1 SCAR=1.2
37 }
38  
39 # set hinthash
40 6 $^H{$class} = 'dan';
41  
42 # set option
43 6 my $pkg = caller;
44 6 $SINGLETON->{code}->{$pkg} = \%opts;
45  
46 # swapping to utf8 hint bits
47 6 $DEFAULT_UTF8HINTBITS = 0;
48 6 ▶ if ($opts{force} && $^H & $utf8_hint_bits) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"force"} and $^H & $utf8_hint_bits) 0 6 6
Condition33%1/3
$opts{"force"} and $^H & $utf8_hint_bits
!ll&&!rl&&r
600
MC/DC0%0/2
$opts{"force"} and $^H & $utf8_hint_bits
$opts{"force"} $^H & $utf8_hint_bits
Truth table33%1/3
A and B
A= $opts{"force"}B= $^H & $utf8_hint_bits
ABresult
0X0
100
111
49 0 $DEFAULT_UTF8HINTBITS = 1;
50 0 $^H &= ~$utf8_hint_bits;
51 }
52  
53 # swapping to encoding
54 6 $DEFAULT_ENCODING = ${^ENCODING};
55 6 ${^ENCODING} = $SINGLETON;
56 }
57  
58 0 ▶sub unimport {
Subroutine unimport: not called CC=3 SCAR=24.8
59 0 my $class = shift;
60 0 undef $^H{$class};
61 0 my $pkg = caller;
62 0 delete $SINGLETON->{code}->{$pkg};
63  
64 0 ▶ if ($DEFAULT_UTF8HINTBITS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DEFAULT_UTF8HINTBITS) 0 0 0
65 0 $DEFAULT_UTF8HINTBITS = 0;
66 0 $^H |= $utf8_hint_bits;
67 }
68 0 ▶ ${^ENCODING} = $DEFAULT_ENCODING || ${^ENCODING};
Condition0%0/3
$DEFAULT_ENCODING || ${^ENCODING}
l!l&&r!l&&!r
000
MC/DC0%0/2
$DEFAULT_ENCODING || ${^ENCODING}
$DEFAULT_ENCODING ${^ENCODING}
Truth table0%0/3
A || B
A= $DEFAULT_ENCODINGB= ${^ENCODING}
ABresult
1X1
011
000
69 }
70  
71  
72 0 ▶sub is_dan {
Subroutine is_dan: not called CC=2 SCAR=17.9
Pod undocumented
73 0 ▶ my $level = $_[1] // 1;
Condition0%0/2
$_[1] // 1
l!l
00
MC/DC0%0/1
$_[1] // 1
$_[1]
Truth table0%0/2
A
A= $_[1]
Aresult
11
00
74 0 my $hinthash = (caller($level))[10];
75 0 $hinthash->{"" . __PACKAGE__};
76 }
77  
78 0 ▶sub run {
Subroutine run: not called CC=6 SCAR=37.4
Pod undocumented
79 0 my($self, $mode, $str, %opts) = @_;
80 0 ▶ my $level = $opts{level} // 1;
Condition0%0/2
$opts{"level"} // 1
l!l
00
MC/DC0%0/1
$opts{"level"} // 1
$opts{"level"}
Truth table0%0/2
A
A= $opts{"level"}
Aresult
11
00
81 0 my $pkg = (caller($level))[0];
82 0 ▶ my $code = ($SINGLETON->{code}->{$pkg} || {})->{$mode} || '';
Condition0%0/4
+($dan::SINGLETON->{'code'}{$pkg} || {})->{$mode} || ''
l!l
00
$dan::SINGLETON->{'code'}{$pkg} || {}
l!l
00
MC/DC0%0/1
+($dan::SINGLETON->{'code'}{$pkg} || {})->{$mode} || ''
$dan::SINGLETON->{'code'}{$pkg}
Truth table0%0/2
A
A= $dan::SINGLETON->{'code'}{$pkg}
Aresult
11
00
83 0 ▶ return $code if $opts{wantcode};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"wantcode"} 0 0 0
84  
85 0 ▶ return '' unless ref($code) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $code eq "CODE" 0 0 0
86 0 return $code->($str);
87 }
88  
89 # for DATA / END section
90 0 ▶sub name { $LATIN1->name }
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
91  
92 0 ▶sub decode {
Subroutine decode: not called CC=2 SCAR=17.9
Pod undocumented
93 0 my $self = shift;
94 0 ▶ if ($self->is_dan) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_dan) { } 0 0 0
95 0 my($str) = @_;
96 0 $self->run( decode => $str );
97 } else {
98 0 $LATIN1->decode(@_);
99 }
100 }
101  
102 0 ▶sub cat_decode {
Subroutine cat_decode: not called CC=4 SCAR=30.0
Pod documented
103 0 my $self = shift;
104  
105 0 ▶ if ($self->is_dan) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_dan) { } 0 0 0
106 0 my(undef, undef, $idx, $quot) = @_;
107 0 my ( $rdst, $rsrc, $rpos ) = \@_[ 0, 1, 2 ];
108 0 my $pos = $idx;
109 0 ▶ while ((my $tmp = index $$rsrc, $quot, $pos) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $tmp = index($$rsrc, $quot, $pos)) > 0) 0 0 0
110 0 $pos = $tmp + 1;
111 0 ▶ last unless substr($$rsrc, $tmp - 1, 1) eq "\\";
Branch: 1 branch
BranchTrueFalseTotal
unless substr($$rsrc, $tmp - 1, 1) eq "\\" 0 0 0
112 }
113 0 $$rpos = $pos;
114  
115 0 my $capt = substr($$rsrc, $idx, ($pos - $idx) - 1);
116 0 $$rdst = $self->run( cat_decode => $capt ) . $quot;
117 0 1;
118 } else {
119 0 $LATIN1->cat_decode(@_);
120 }
121 }
122  
123 7 1;
124 __END__
↑ Summary