File: Nameprep.pm

package info (click to toggle)
libnet-idn-nameprep-perl 1.102%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 104 kB
  • sloc: perl: 56; makefile: 2
file content (139 lines) | stat: -rwxr-xr-x 3,021 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package Net::IDN::Nameprep;

use strict;
use utf8;
use warnings;

our $VERSION = "1.102";
$VERSION = eval $VERSION;

require Exporter;
our @ISA    = qw(Exporter);
our @EXPORT = qw(nameprep);

use Unicode::Stringprep 1.1;

use Unicode::Stringprep::Mapping;
use Unicode::Stringprep::Prohibited;

our $_nameprep_stored;
our $_nameprep_query;

sub nameprep {
  my ($input, %param) = @_;
  if (
      !exists($param{'AllowUnassigned'})
   || $param{'AllowUnassigned'}
  ) {
    goto &$_nameprep_query;
  } else {
    goto &$_nameprep_stored;
  }
}

BEGIN {
  my @_common_args = (
    3.2,
    [
      @Unicode::Stringprep::Mapping::B1,
      @Unicode::Stringprep::Mapping::B2
    ],
    'KC',
    [
      @Unicode::Stringprep::Prohibited::C12,
      @Unicode::Stringprep::Prohibited::C22,
      @Unicode::Stringprep::Prohibited::C3,
      @Unicode::Stringprep::Prohibited::C4,
      @Unicode::Stringprep::Prohibited::C5,
      @Unicode::Stringprep::Prohibited::C6,
      @Unicode::Stringprep::Prohibited::C7,
      @Unicode::Stringprep::Prohibited::C8,
      @Unicode::Stringprep::Prohibited::C9
    ],
    1,
  );

  our $_nameprep_stored = Unicode::Stringprep->new(
    @_common_args,
    1,
  );

  our $_nameprep_query = Unicode::Stringprep->new(
    @_common_args,
    0,
  );
}

1;
__END__

=encoding UTF-8

=head1 NAME

Net::IDN::Nameprep - A Stringprep Profile for Internationalized Domain Names (S<RFC 3491>)

=head1 SYNOPSIS

  use Net::IDN::Nameprep;
  $output = nameprep $input;

=head1 DESCRIPTION

This module implements the I<nameprep> specification, which describes how to
prepare internationalized domain name (IDN) labels in order to increase the
likelihood that name input and name comparison work in ways that make sense for
typical users throughout the world.  Nameprep is a profile of the stringprep
protocol and is used as part of a suite of on-the-wire protocols for
internationalizing the Domain Name System (DNS).

=head1 FUNCTIONS

This module implements a single function, C<nameprep>, which is exported by default.

=over

=item nameprep( $input [, AllowUnassigned => 1 ] )

Processes C<$input> according to the I<nameprep> specification and
returns the result.

If C<$input> contains characters not allowed for I<nameprep>, it
throws an exception (so use C<eval> if necessary).

This function takes the following optional parameter:

=over

=item AllowUnassigned

(boolean) If set to a false value, unassigned code points in C<$input> are not allowed.

False MUST be used for I<stored strings>.

True MAY be used for I<queries>.

The default is true (backwards compatibility).

=back

=back

=head1 AUTHOR

Claus FE<auml>rber <CFAERBER@cpan.org>

Previous versions written by Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>

=head1 LICENSE

Copyright 2007-2015 Claus FE<auml>rber.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 SEE ALSO

L<Unicode::Stringprep>, S<RFC 3491> (L<http://www.ietf.org/rfc/rfc3491.txt>)

=cut