root/Net-IDN-Nameprep/trunk/lib/Net/IDN/Nameprep.pm

Revision 319 (checked in by miyagawa, 19 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 package Net::IDN::Nameprep;
2
3 use strict;
4 require v5.6.0;
5 our $VERSION = '0.01';
6 our @ISA    = qw(Exporter);
7 our @EXPORT = qw(nameprep);
8
9 use Net::IDN::Nameprep::Mapping;
10 use Net::IDN::Nameprep::Prohibited;
11
12 use Unicode::Normalize;
13
14 sub mapping {
15     my $input = shift;
16     my $mapped;
17     for my $i (0..length($input)-1) {
18         my $char = substr($input, $i, 1);
19         $mapped .= chr(Net::IDN::Nameprep::Mapping->mapping(ord($char)));
20     }
21     return $mapped;
22 }
23
24 sub check_prohibited {
25     my $input = shift;
26     for my $i (0..length($input)-1) {
27         my $char = substr($input, $i, 1);
28         if (Net::IDN::Nameprep::Prohibited->prohibited(ord($char))) {
29             require Carp;
30             Carp::croak("String $input contains prohibited character: $char");
31         }
32     }
33 }
34
35 sub nameprep {
36     my $input = shift;
37     my $output = NFKC mapping $input;
38     check_prohibited $output;
39     return $output;
40 }
41
42 1;
43 __END__
44
45 =head1 NAME
46
47 Net::IDN::Nameprep - IDN nameprep tools
48
49 =head1 SYNOPSIS
50
51   use Net::IDN::Nameprep;
52   $output = nameprep $input;
53
54 =head1 DESCRIPTION
55
56 B<THIS IS ALPHA SOFTWARE. NEEDS MORE TESTING!>
57
58 Net::IDN::Nameprep implements IDN nameprep specification. This module
59 exports only one function called C<nameprep>.
60
61 There comes C<NO WARRANTY> with this module.
62
63 =head1 FUNCTIONS
64
65 =over 4
66
67 =item nameprep
68
69   $prepared = nameprep $utf8;
70
71 accepts UTF8 encoded string, and returns nameprep-ed UTF8 encoded
72 string. It might throw an exception in case of error ("String %s
73 contains prohibited character: %s").
74
75 =back
76
77 =head1 BUGS
78
79 There may be plenty of Bugs. Please lemme know if you find any.
80
81 =head1 AUTHOR
82
83 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
84
85 This library is free software; you can redistribute it and/or modify
86 it under the same terms as Perl itself.
87
88 =head1 SEE ALSO
89
90 L<Unicode::Normalize>, L<Convert::RACE>, L<Convert::DUDE>, http://www.i-d-n.net/draft/draft-ietf-idn-nameprep-03.txt
91
92 =cut
Note: See TracBrowser for help on using the browser.