4 die "Encode::Tcl not supported on EBCDIC\n";
8 our $VERSION = do { my @r = (q$Revision: 0.90 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
10 use Encode qw(find_encoding);
11 use base 'Encode::Encoding';
16 foreach my $dir (@INC)
18 if (opendir(my $dh,"$dir/Encode"))
20 while (defined(my $name = readdir($dh)))
22 if ($name =~ /^(.*)\.enc$/)
25 my $obj = find_encoding($canon, 1); # skip external tables
28 my $obj = bless { Name => $canon, File => "$dir/Encode/$name"},__PACKAGE__;
29 $obj->Define( $canon );
30 # warn "$canon => $obj\n";
44 sub no_map_in_encode ($$)
45 # codepoint, enc-name;
47 carp sprintf "\"\\N{U+%x}\" does not map to %s", @_;
48 # /* FIXME: Skip over the character, copy in replacement and continue
49 # * but that is messy so for now just fail.
54 sub no_map_in_decode ($$)
55 # enc-name, string beginning the malform char;
57 # /* UTF-8 is supposed to be "Universal" so should not happen */
58 croak sprintf "%s '%s' does not map to UTF-8", @_;
64 my $new = $obj->loadEncoding;
65 return undef unless (defined $new);
66 return $new->encode(@_);
72 my $new = $obj->loadEncoding;
73 return undef unless (defined $new);
74 return $new->new_sequence(@_);
80 my $new = $obj->loadEncoding;
81 return undef unless (defined $new);
82 return $new->decode(@_);
88 my $file = $obj->{'File'};
89 my $name = $obj->name;
90 if (open(my $fh,$file))
96 $type = substr($line,0,1);
97 last unless $type eq '#';
100 ($type eq 'X') ? 'Extended' :
101 ($type eq 'E') ? 'Escape' : 'Table';
102 my $class = ref($obj) . '::' . $subclass;
103 # carp "Loading $file";
105 return $obj if $obj->read($fh,$obj->name,$type);
109 croak("Cannot open $file for ".$obj->name);
111 $obj->Undefine($name);
117 my ($class,$name) = @_;
119 foreach my $dir (@INC)
121 last if ($enc = $class->loadEncoding($name,"$dir/Encode/$name.enc"));
126 require Encode::Tcl::Table;
127 require Encode::Tcl::Escape;
128 require Encode::Tcl::Extended;
135 Encode::Tcl - Tcl encodings
141 $unicode = decode('shiftjis', $shiftjis);
142 $shiftjis = encode('shiftjis', $unicode);
146 This module provides the interface to encodings
147 defined by the format of encoding tables borrowed from Tcl
148 and not compiled in other Encode:: modules.
150 See also F<Encode/EncodeFormat.pod> and F<Encode/*.enc> files.
152 To find how to use this module in detail, see L<Encode>.
158 L<Encode::Tcl::Table>
160 L<Encode::Tcl::Escape>
162 L<Encode::Tcl::Extended>