blib/lib/Net/IDN/Encode.pm

filter: Statementstmt 100% 60 / 60 Branchbran 78.1% 25 / 32 Conditioncond 50.0% 7 / 14 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 100% 16 / 16 Podpod 75.0% 6 / 8 totaltotal 84.7% 117 / 138 CC 21 SCAR 19.0
CC
21
Cov
87%
_email
14.8
to_ascii
5.2
_domain
4.0
CRAP 6.7
« blib/lib/Net/IDN/Punycode/PP.pm ↑ Summary blib/lib/Net/IDN/UTS46/_Mapping.pm »
1 package Net::IDN::Encode;
2  
3 15 require 5.006;
4  
5 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 15 our $VERSION = "2.600";
10 15 $VERSION = eval $VERSION;
11  
12 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 15 our @ISA = ('Exporter');
16 15 our @EXPORT = ();
17 15 our %EXPORT_TAGS = (
18 'all' => [
19 'to_ascii',
20 'to_unicode',
21 'domain_to_ascii',
22 'domain_to_unicode',
23 'email_to_ascii',
24 'email_to_unicode',
25 ],
26 '_var' => [
27 '$IDNA_PREFIX',
28 'IsIDNADot',
29 'IsIDNAAtsign',
30 ]
31 );
32 15 Exporter::export_ok_tags(keys %EXPORT_TAGS);
33  
34 15 ▶use Net::IDN::Punycode 1.102 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 15 our $IDNA_PREFIX = 'xn--';
37 15 ▶sub IsIDNADot { "002E\n3002\nFF0E\nFF61" }
Subroutine IsIDNADot: called CC=1 SCAR=0.0
Pod undocumented
38 15 ▶sub IsIDNAAtsign{ "0040\nFE6B\nFF20" }
Subroutine IsIDNAAtsign: called CC=1 SCAR=0.0
Pod undocumented
39  
40 15 require Net::IDN::UTS46; # after declaration of vars!
41  
42 88 ▶sub to_ascii {
Subroutine to_ascii: called CC=5 SCAR=16.5
Pod documented
43 88 my($label,%param) = @_;
44 88 ▶ croak 'Invalid label' if $label =~ m/\p{IsIDNADot}/o;
Branch: 1 branch
BranchTrueFalseTotal
if $label =~ /\p{IsIDNADot}/o 0 88 88
45  
46 88 ▶ if($label =~ m/\P{ASCII}/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label =~ /\P{ASCII}/o) { } 16 72 88
47 16 $label = Net::IDN::UTS46::to_ascii(@_);
48 } else {
49 72 ▶ croak 'label empty' if length($label) < 1;
Branch: 1 branch
BranchTrueFalseTotal
if length $label < 1 0 72 72
50 72 ▶ croak 'label too long' if length($label) > 63;
Branch: 1 branch
BranchTrueFalseTotal
if length $label > 63 0 72 72
51 }
52 87 return $label;
53 }
54  
55 91 ▶sub to_unicode {
Subroutine to_unicode: called CC=3 SCAR=11.0
Pod documented
56 91 my($label,%param) = @_;
57 91 ▶ croak 'Invalid label' if $label =~ m/\p{IsIDNADot}/o;
Branch: 1 branch
BranchTrueFalseTotal
if $label =~ /\p{IsIDNADot}/o 0 91 91
58  
59 91 ▶ if($label =~ m/\P{ASCII}|^(?:(?i)$IDNA_PREFIX)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label =~ /\P{ASCII}|^(?:(?i)$Net::IDN::Encode::IDNA_PREFIX)/o) 29 62 91
60 29 $label = Net::IDN::UTS46::to_unicode(@_);
61 }
62 89 return $label;
63 }
64  
65 56 ▶sub _domain {
Subroutine _domain: called CC=4 SCAR=13.9
66 56 my ($domain,$to_function,$ascii,%param) = @_;
67 56 ▶ $param{'UseSTD3ASCIIRules'} = 1 unless exists $param{'UseSTD3ASCIIRules'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $param{"UseSTD3ASCIIRules"} 48 8 56
68  
69 56 my $even_odd = 1;
70 return join '',
71 56 ▶ map { $even_odd++ % 2 ? $to_function->($_, %param) : $ascii ? '.' : $_ }
Branch: 2 branches
BranchTrueFalseTotal
$even_odd++ % 2 ? : 165 109 274
$ascii ? : 54 55 109
72 split /(\p{IsIDNADot})/o, $domain;
73 }
74  
75 26 ▶sub _email {
Subroutine _email: called CC=12 SCAR=27.0
76 26 my ($email,$to_function,$ascii,%param) = @_;
77 26 ▶ return $email if !defined($email) || $email eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $email or $email eq "" 8 18 26
Condition100%3/3
not defined $email or $email eq ""
l!l&&r!l&&!r
4418
MC/DC100%2/2
not defined $email or $email eq ""
not defined $email $email eq ""
Truth table100%3/3
not(A) or B
A= not defined $emailB= $email eq ""
ABresult
1X1
011
000
78  
79 18 ▶ $email =~ m/^(
Branch: 1 branch
BranchTrueFalseTotal
$email =~ /^( (?(?!\p{IsIDNAAtsign}|").|(?!))+ | "(?:(?:[^"]|\\.)*[^\\])?" ) (?: (\p{IsIDNAAtsign}) (?:([^\[\]]*)|(\[.*\]))? )?$/ox or croak("Invalid email address") 18 0 18
80 (?(?!\p{IsIDNAAtsign}|").|(?!))+
81 |
82 "(?:(?:[^"]|\\.)*[^\\])?"
83 )
84 (?:
85 (\p{IsIDNAAtsign})
86 (?:([^\[\]]*)|(\[.*\]))?
87 )?$/xo || croak "Invalid email address";
88 18 my($local_part,$at,$domain,$domain_literal) = ($1,$2,$3);
89  
90 18 ▶ $local_part =~ m/\P{ASCII}/ && croak "Non-ASCII characters in local-part";
Branch: 1 branch
BranchTrueFalseTotal
$local_part =~ /\P{ASCII}/ and croak("Non-ASCII characters in local-part") 0 18 18
91 18 ▶ $domain_literal =~ m/\P{ASCII}/ && croak "Non-ASCII characters in domain-literal" if $domain_literal;
Branch: 1 branch
BranchTrueFalseTotal
if $domain_literal 0 18 18
Condition20%1/5
$domain_literal && ($domain_literal =~ /\P{ASCII}/ && croak('Non-ASCII characters in domain-literal'))
!ll&&!rl&&r
1800
$domain_literal =~ /\P{ASCII}/ and croak("Non-ASCII characters in domain-literal")
!ll
00
MC/DC0%0/2
$domain_literal && ($domain_literal =~ /\P{ASCII}/ && croak('Non-ASCII characters in domain-literal'))
$domain_literal $domain_literal =~ /\P{ASCII}/
Truth table33%1/3
A && B
A= $domain_literalB= $domain_literal =~ /\P{ASCII}/
ABresult
0X0
100
111
92  
93 18 ▶ $domain = $to_function->($domain,%param) if $domain;
Branch: 1 branch
BranchTrueFalseTotal
if $domain 14 4 18
94 18 ▶ $at = '@' if $ascii;
Branch: 1 branch
BranchTrueFalseTotal
if $ascii 9 9 18
95  
96 18 ▶ return ($domain || $domain_literal)
Branch: 1 branch
BranchTrueFalseTotal
$domain || $domain_literal ? : 14 4 18
Condition50%3/6
$domain or $domain_literal
l!l&&r!l&&!r
1404
$domain || $domain_literal
l!l&&r!l&&!r
1400
MC/DC50%1/2
$domain or $domain_literal
$domain $domain_literal
MC/DC0%0/2
$domain || $domain_literal
$domain $domain_literal
Truth table66%2/3
A or B
A= $domainB= $domain_literal
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $domainB= $domain_literal
ABresult
1X1
011
000
97 ? ($local_part.$at.($domain || $domain_literal))
98 : ($local_part);
99 }
100  
101 27 ▶sub domain_to_ascii { _domain(shift, \&to_ascii, 1, @_) }
Subroutine domain_to_ascii: called CC=1 SCAR=0.0
Pod documented
102 29 ▶sub domain_to_unicode { _domain(shift, \&to_unicode, 0, @_) }
Subroutine domain_to_unicode: called CC=1 SCAR=0.0
Pod documented
103  
104 13 ▶sub email_to_ascii { _email(shift, \&domain_to_ascii, 1, @_) }
Subroutine email_to_ascii: called CC=1 SCAR=0.0
Pod documented
105 13 ▶sub email_to_unicode { _email(shift, \&domain_to_unicode, 0, @_) }
Subroutine email_to_unicode: called CC=1 SCAR=0.0
Pod documented
106  
107 15 1;
108  
109 __END__
« blib/lib/Net/IDN/Punycode/PP.pm ↑ Summary blib/lib/Net/IDN/UTS46/_Mapping.pm »