| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::IDN::IDNA2003; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 5 |  |  | 5 |  | 188481 | use strict; | 
|  | 5 |  |  |  |  | 10 |  | 
|  | 5 |  |  |  |  | 467 |  | 
| 4 | 5 |  |  | 5 |  | 2106 | use utf8; | 
|  | 5 |  |  |  |  | 26 |  | 
|  | 5 |  |  |  |  | 31 |  | 
| 5 | 5 |  |  | 5 |  | 145 | use warnings; | 
|  | 5 |  |  |  |  | 11 |  | 
|  | 5 |  |  |  |  | 324 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = "1.000"; | 
| 8 |  |  |  |  |  |  | $VERSION = eval $VERSION; | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 5 |  |  | 5 |  | 26 | use Carp; | 
|  | 5 |  |  |  |  | 10 |  | 
|  | 5 |  |  |  |  | 344 |  | 
| 11 | 5 |  |  | 5 |  | 25 | use Exporter; | 
|  | 5 |  |  |  |  | 11 |  | 
|  | 5 |  |  |  |  | 155 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 5 |  |  | 5 |  | 4617 | use Net::IDN::Nameprep 1.1 (); | 
|  | 5 |  |  |  |  | 1034723 |  | 
|  | 5 |  |  |  |  | 1775 |  | 
| 14 | 5 |  |  | 5 |  | 5968 | use Net::IDN::Punycode 1 (); | 
|  | 5 |  |  |  |  | 10449 |  | 
|  | 5 |  |  |  |  | 755 |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | our @ISA = ('Exporter'); | 
| 17 |  |  |  |  |  |  | our @EXPORT = (); | 
| 18 |  |  |  |  |  |  | our @EXPORT_OK = ( | 
| 19 |  |  |  |  |  |  | 'idna2003_to_ascii', | 
| 20 |  |  |  |  |  |  | 'idna2003_to_unicode', | 
| 21 |  |  |  |  |  |  | ); | 
| 22 |  |  |  |  |  |  | our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | our $IDNA_prefix; | 
| 25 |  |  |  |  |  |  | *IDNA_prefix = \'xn--'; | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub idna2003_to_ascii { | 
| 28 | 5 |  |  | 5 |  | 2368 | use bytes; | 
|  | 5 |  |  |  |  | 31 |  | 
|  | 5 |  |  |  |  | 46 |  | 
| 29 | 5 |  |  | 5 |  | 166 | no warnings qw(utf8); # needed for perl v5.6.x | 
|  | 5 |  |  |  |  | 11 |  | 
|  | 5 |  |  |  |  | 1852 |  | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 48 |  |  | 48 | 1 | 14566 | my ($label,%param) = @_; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 48 | 100 |  |  |  | 219 | $param{'AllowUnassigned'} = 0 unless exists $param{'AllowUnassigned'}; | 
| 34 | 48 | 100 |  |  |  | 292 | $param{'UseSTD3ASCIIRules'} = 1 unless exists $param{'UseSTD3ASCIIRules'}; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 48 | 100 |  |  |  | 211 | if($label =~ m/[^\x00-\x7F]/) { | 
| 37 | 38 |  |  |  |  | 175 | $label = Net::IDN::Nameprep::nameprep($label,%param); | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 36 | 100 |  |  |  | 11549 | if($param{'UseSTD3ASCIIRules'}) { | 
| 41 | 26 | 100 | 66 |  |  | 1260 | croak 'Invalid label (toASCII, step 3)' if | 
|  |  |  | 100 |  |  |  |  | 
| 42 |  |  |  |  |  |  | $label =~ m/^-/ || | 
| 43 |  |  |  |  |  |  | $label =~ m/-$/ || | 
| 44 |  |  |  |  |  |  | $label =~ m/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]/; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 32 | 100 |  |  |  | 125 | if($label =~ m/[^\x00-\x7F]/) { | 
| 48 | 21 | 100 |  |  |  | 571 | croak 'Invalid label (toASCII, step 5)' if $label =~ m/^$IDNA_prefix/io; | 
| 49 | 20 |  |  |  |  | 123 | $label = $IDNA_prefix.(Net::IDN::Punycode::encode_punycode($label)); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 31 | 100 | 66 |  |  | 683 | croak 'Invalid label length (toASCII, step 8)' if | 
| 53 |  |  |  |  |  |  | length($label) < 1 || | 
| 54 |  |  |  |  |  |  | length($label) > 63; | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 28 |  |  |  |  | 151 | return $label; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | sub idna2003_to_unicode { | 
| 60 | 5 |  |  | 5 |  | 74 | use bytes; | 
|  | 5 |  |  |  |  | 11 |  | 
|  | 5 |  |  |  |  | 22 |  | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 30 |  |  | 30 | 1 | 16397 | my ($label,%param) = @_; | 
| 63 | 30 |  |  |  |  | 74 | my $orig = $label; | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 30 | 100 |  |  |  | 96 | $param{'AllowUnassigned'} = 0 unless exists $param{'AllowUnassigned'}; | 
| 66 | 30 | 100 |  |  |  | 83 | $param{'UseSTD3ASCIIRules'} = 1 unless exists $param{'UseSTD3ASCIIRules'}; | 
| 67 |  |  |  |  |  |  |  | 
| 68 | 30 |  | 100 |  |  | 43 | return eval { | 
| 69 |  |  |  |  |  |  | if($label =~ m/[^\x00-\x7F]/) { | 
| 70 |  |  |  |  |  |  | $label = Net::IDN::Nameprep::nameprep($label,%param); | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | my $save3 = $label; | 
| 74 |  |  |  |  |  |  | croak 'Missing IDNA prefix (ToUnicode, step 3)' | 
| 75 |  |  |  |  |  |  | unless $label =~ s/^$IDNA_prefix//io; | 
| 76 |  |  |  |  |  |  | $label = Net::IDN::Punycode::decode_punycode($label); | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | my $save6 = to_ascii($label,%param); | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | croak 'Invalid label (ToUnicode, step 7)' unless uc($save6) eq uc($save3); | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | $label; | 
| 83 |  |  |  |  |  |  | } || $orig; | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | *to_unicode = \&idna2003_to_unicode; | 
| 87 |  |  |  |  |  |  | *to_ascii = \&idna2003_to_ascii; | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | 1; | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | __END__ |