blib/lib/AnyEvent/Util/idna.pl

filter: Statementstmt 100% 75 / 75 Branchbran 88.4% 23 / 26 Conditioncond 71.4% 5 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 8 / 8 Podpod 66.6% 2 / 3 totaltotal 92.6% 114 / 123 CC 17 SCAR 18.3
CC
17
Cov
95%
punycode_encode
10.0
punycode_decode
6.0
pyc_adapt
3.0
CRAP 6.3
« blib/lib/AnyEvent/Impl/Glib.pm ↑ Summary blib/lib/AnyEvent/Impl/Tk.pm »
1 # based on RFC 3492
2  
3 1 ▶use AnyEvent (); BEGIN { AnyEvent::common_sense }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub pyc_base () { 36 }
9 sub pyc_tmin () { 1 }
10 sub pyc_tmax () { 26 }
11 sub pyc_initial_bias () { 72 }
12 sub pyc_initial_n () { 128 }
13  
14 sub pyc_digits () { "abcdefghijklmnopqrstuvwxyz0123456789" }
15  
16 12 ▶sub pyc_adapt($$$) {
Subroutine pyc_adapt: called CC=3 SCAR=11.0
Pod undocumented
17 12 my ($delta, $numpoints, $firsttime) = @_;
18  
19 12 ▶ $delta = $firsttime ? $delta / 700 : $delta >> 1;
Branch: 1 branch
BranchTrueFalseTotal
$firsttime ? : 7 5 12
20 12 $delta += $delta / $numpoints;
21  
22 12 my $k;
23  
24 12 ▶ while ($delta > (pyc_base - pyc_tmin) * pyc_tmax / 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delta > 455) 6 12 18
25 6 $delta /= pyc_base - pyc_tmin;
26 6 $k += pyc_base;
27 }
28  
29 12 $k + $delta * (pyc_base - pyc_tmin + 1) / ($delta + 38)
30 }
31  
32 5 ▶sub punycode_encode($) {
Subroutine punycode_encode: called CC=10 SCAR=23.0
Pod documented
33 5 my ($input) = @_;
34  
35 5 my ($n, $bias, $delta) = (pyc_initial_n, pyc_initial_bias);
36  
37 5 (my $output = $input) =~ y/\x00-\x7f//cd;
38 5 my $h = my $b = length $output;
39  
40 5 my @input = split '', $input;
41  
42 5 ▶ $output .= "-" if $b && $h < @input;
Branch: 1 branch
BranchTrueFalseTotal
if $b and $h < @input 3 2 5
Condition66%2/3
$b and $h < @input
!ll&&!rl&&r
203
MC/DC50%1/2
$b and $h < @input
$b $h < @input
Truth table66%2/3
A and B
A= $bB= $h < @input
ABresult
0X0
100
111
43  
44 5 ▶ while ($h < @input) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h < @input) 9 5 14
45 9 my $m = List::Util::min grep { $_ >= $n } map ord, @input;
46  
47 9 ▶ $m - $n <= (0x7fffffff - $delta) / ($h + 1)
Branch: 1 branch
BranchTrueFalseTotal
$m - $n <= (2147483647 - $delta) / ($h + 1) or Carp::croak("punycode_encode: overflow in punycode delta encoding") 9 0 9
48 or Carp::croak "punycode_encode: overflow in punycode delta encoding";
49 9 $delta += ($m - $n) * ($h + 1);
50 9 $n = $m;
51  
52 9 for my $i (@input) {
53 25 my $c = ord $i;
54 25 ▶ ++$delta < 0x7fffffff
Branch: 1 branch
BranchTrueFalseTotal
if $c < $n 11 14 25
Condition75%3/4
$c < $n && (++$delta < 2147483647 || Carp::croak('punycode_encode: overflow in punycode delta encoding'))
!ll
1411
++$delta < 2147483647 or Carp::croak("punycode_encode: overflow in punycode delta encoding")
l!l
110
MC/DC0%0/2
$c < $n && (++$delta < 2147483647 || Carp::croak('punycode_encode: overflow in punycode delta encoding'))
$c < $n ++$delta < 2147483647
Truth table33%1/3
A && B
A= $c < $nB= ++$delta < 2147483647
ABresult
0X0
100
111
55 or Carp::croak "punycode_encode: overflow in punycode delta encoding"
56 if $c < $n;
57  
58 25 ▶ if ($c == $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c == $n) 9 16 25
59 9 my ($q, $k) = ($delta, pyc_base);
60  
61 9 while () {
62 29 my $t = List::Util::min pyc_tmax, List::Util::max pyc_tmin, $k - $bias;
63  
64 29 ▶ last if $q < $t;
Branch: 1 branch
BranchTrueFalseTotal
if $q < $t 9 20 29
65  
66 20 $output .= substr pyc_digits, $t + (($q - $t) % (pyc_base - $t)), 1;
67  
68 20 $q = ($q - $t) / (pyc_base - $t);
69 20 $k += pyc_base;
70 }
71  
72 9 $output .= substr pyc_digits, $q, 1;
73  
74 9 $bias = pyc_adapt $delta, $h + 1, $h == $b;
75  
76 9 $delta = 0;
77 9 ++$h;
78 }
79 }
80  
81 9 ++$delta;
82 9 ++$n;
83 }
84  
85 $output
86 5 }
87  
88 2 ▶sub punycode_decode($) {
Subroutine punycode_decode: called CC=6 SCAR=17.9
Pod documented
89 2 my ($input) = @_;
90  
91 2 my ($n, $bias, $i) = (pyc_initial_n, pyc_initial_bias);
92 2 my $output;
93  
94 2 ▶ if ($input =~ /^(.*?)-([^-]*)$/x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /^(.*?)-([^-]*)$/x) 1 1 2
95 1 $output = $1;
96 1 $input = $2;
97  
98 1 ▶ $output =~ /[^\x00-\x7f]/
Branch: 1 branch
BranchTrueFalseTotal
$output =~ /[^\x00-\x7f]/ and Carp::croak("punycode_decode: malformed punycode") 0 1 1
99 and Carp::croak "punycode_decode: malformed punycode";
100 }
101  
102 2 ▶ while (length $input) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $input) 3 2 5
103 3 my $oldi = $i;
104 3 my $w = 1;
105  
106 3 for (my $k = pyc_base; ; $k += pyc_base) {
107 9 ▶ (my $digit = index pyc_digits, substr $input, 0, 1, "")
Branch: 1 branch
BranchTrueFalseTotal
(my $digit = index("abcdefghijklmnopqrstuvwxyz0123456789", substr($input, 0, 1, ''))) >= 0 or Carp::croak("punycode_decode: malformed punycode") 9 0 9
108 >= 0
109 or Carp::croak "punycode_decode: malformed punycode";
110
111 9 $i += $digit * $w;
112
113 9 my $t = List::Util::max pyc_tmin, List::Util::min pyc_tmax, $k - $bias;
114 9 ▶ last if $digit < $t;
Branch: 1 branch
BranchTrueFalseTotal
if $digit < $t 3 6 9
115  
116 6 $w *= pyc_base - $t;
117 }
118  
119 3 my $outlen = 1 + length $output;
120 3 $bias = pyc_adapt $i - $oldi, $outlen, $oldi == 0;
121  
122 3 $n += $i / $outlen;
123 3 $i %= $outlen;
124  
125 3 substr $output, $i, 0, chr $n;
126 3 ++$i;
127 }
128  
129 $output
130 2 }
131  
132 1 1
« blib/lib/AnyEvent/Impl/Glib.pm ↑ Summary blib/lib/AnyEvent/Impl/Tk.pm »