4 die "Encode::Tcl not supported on EBCDIC\n";
8 our $VERSION = do {my @r=(q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r};
9 use Encode qw(find_encoding);
10 use base 'Encode::Encoding';
15 foreach my $dir (@INC)
17 if (opendir(my $dh,"$dir/Encode"))
19 while (defined(my $name = readdir($dh)))
21 if ($name =~ /^(.*)\.enc$/)
24 my $obj = find_encoding($canon, 1); # skip external tables
27 my $obj = bless { Name => $canon, File => "$dir/Encode/$name"},__PACKAGE__;
28 $obj->Define( $canon );
29 # warn "$canon => $obj\n";
43 sub no_map_in_encode ($$)
44 # codepoint, enc-name;
46 carp sprintf "\"\\N{U+%x}\" does not map to %s", @_;
47 # /* FIXME: Skip over the character, copy in replacement and continue
48 # * but that is messy so for now just fail.
53 sub no_map_in_decode ($$)
54 # enc-name, string beginning the malform char;
56 # /* UTF-8 is supposed to be "Universal" so should not happen */
57 croak sprintf "%s '%s' does not map to UTF-8", @_;
63 my $new = $obj->loadEncoding;
64 return undef unless (defined $new);
65 return $new->encode(@_);
71 my $new = $obj->loadEncoding;
72 return undef unless (defined $new);
73 return $new->new_sequence(@_);
79 my $new = $obj->loadEncoding;
80 return undef unless (defined $new);
81 return $new->decode(@_);
87 my $file = $obj->{'File'};
88 my $name = $obj->name;
89 if (open(my $fh,$file))
95 $type = substr($line,0,1);
96 last unless $type eq '#';
99 ($type eq 'X') ? 'Extended' :
100 ($type eq 'E') ? 'Escape' : 'Table';
101 my $class = ref($obj) . '::' . $subclass;
102 # carp "Loading $file";
104 return $obj if $obj->read($fh,$obj->name,$type);
108 croak("Cannot open $file for ".$obj->name);
110 $obj->Undefine($name);
116 my ($class,$name) = @_;
118 foreach my $dir (@INC)
120 last if ($enc = $class->loadEncoding($name,"$dir/Encode/$name.enc"));
125 require Encode::Tcl::Table;
126 require Encode::Tcl::Escape;
127 require Encode::Tcl::Extended;
134 Encode::Tcl - Tcl encodings
140 $unicode = decode('shiftjis', $shiftjis);
141 $shiftjis = encode('shiftjis', $unicode);
145 This module provides the interface to encodings
146 defined by the format of encoding tables borrowed from Tcl
147 and not compiled in other Encode:: modules.
149 See also F<Encode/EncodeFormat.pod> and F<Encode/*.enc> files.
151 To find how to use this module in detail, see L<Encode>.
157 L<Encode::Tcl::Table>
159 L<Encode::Tcl::Escape>
161 L<Encode::Tcl::Extended>