| 1 | ##---------------------------------------------------------------------------## | ||
| 2 | ## File: | ||
| 3 | ## $Id: CharMaps.pm,v 1.2 2003/03/05 22:17:15 ehood Exp $ | ||
| 4 | ## Author: | ||
| 5 | ## Earl Hood earl@earlhood.com | ||
| 6 | ## Description: | ||
| 7 | ## POD after __END__ | ||
| 8 | ##---------------------------------------------------------------------------## | ||
| 9 | ## Copyright (C) 1997-2002 Earl Hood, earl@earlhood.com | ||
| 10 | ## | ||
| 11 | ## This program is free software; you can redistribute it and/or modify | ||
| 12 | ## it under the terms of the GNU General Public License as published by | ||
| 13 | ## the Free Software Foundation; either version 2 of the License, or | ||
| 14 | ## (at your option) any later version. | ||
| 15 | ## | ||
| 16 | ## This program is distributed in the hope that it will be useful, | ||
| 17 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | ## GNU General Public License for more details. | ||
| 20 | ## | ||
| 21 | ## You should have received a copy of the GNU General Public License | ||
| 22 | ## along with this program; if not, write to the Free Software | ||
| 23 | ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | ||
| 24 | ## 02111-1307, USA | ||
| 25 | ##---------------------------------------------------------------------------## | ||
| 26 | |||
| 27 | package MHonArc::CharMaps; | ||
| 28 | |||
| 29 | use strict; | ||
| 30 | use vars qw( @ISA @EXPORT %HTMLSpecials $HTMLSpecials ); | ||
| 31 | |||
| 32 | use Carp; | ||
| 33 | use Exporter (); | ||
| 34 | |||
| 35 | our $VERSION = '2.6.24'; | ||
| 36 | |||
| 37 | @ISA = qw( Exporter ); | ||
| 38 | @EXPORT = qw( $HTMLSpecials %HTMLSpecials ); | ||
| 39 | |||
| 40 | # The following two variables need to be in sync. The hash version should | ||
| 41 | # have contain mappings for each character in the scalar version. | ||
| 42 | $HTMLSpecials = "\x22\x26\x3C\x3E"; | ||
| 43 | %HTMLSpecials = ( | ||
| 44 | "\x22" => '"', # ISOnum : Quotation mark | ||
| 45 | "\x26" => '&', # ISOnum : Ampersand | ||
| 46 | "\x3C" => '<', # ISOnum : Less-than sign | ||
| 47 | "\x3E" => '>', # ISOnum : Greater-than sign | ||
| 48 | ); | ||
| 49 | |||
| 50 | sub new { | ||
| 51 | my $self = {}; | ||
| 52 | my $mod = shift; # Name of module | ||
| 53 | my $tbl = shift; # Table of charsets to map files | ||
| 54 | my $class = ref($mod) || $mod; | ||
| 55 | |||
| 56 | $self->{'_maps'} = {}; # Loaded maps | ||
| 57 | $self->{'_tbl'} = $tbl; # charsets -> map files table | ||
| 58 | bless $self, $class; | ||
| 59 | $self; | ||
| 60 | } | ||
| 61 | |||
| 62 | sub set_map { | ||
| 63 | my $self = shift; | ||
| 64 | my $charset = shift; | ||
| 65 | my $map = shift; | ||
| 66 | my $old_map = $self->{'_maps'}{$charset} || undef; | ||
| 67 | $self->{'_maps'}{$charset} = $map; | ||
| 68 | $old_map; | ||
| 69 | } | ||
| 70 | |||
| 71 | sub get_map { | ||
| 72 | my $self = shift; | ||
| 73 | my $charset = shift; | ||
| 74 | |||
| 75 | my $map = $self->{'_maps'}{$charset}; | ||
| 76 | return $map if defined($map); | ||
| 77 | |||
| 78 | my $file = $self->{'_tbl'}{$charset}; | ||
| 79 | if (!defined($file)) { | ||
| 80 | carp 'Warning: Unknown charset: ', $charset, "\n"; | ||
| 81 | $map = $self->{'_maps'}{$charset} = {}; | ||
| 82 | |||
| 83 | } else { | ||
| 84 | delete $INC{$file}; | ||
| 85 | eval { $map = $self->{'_maps'}{$charset} = require $file; }; | ||
| 86 | if ($@) { | ||
| 87 | carp 'Warning: ', $@, "\n"; | ||
| 88 | $map = $self->{'_maps'}{$charset} = {}; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | $map; | ||
| 92 | } | ||
| 93 | |||
| 94 | ##---------------------------------------------------------------------------## | ||
| 95 | 1; | ||
| 96 | __END__ |