File Coverage

blib/lib/Unicode/Map8.pm
Criterion Covered Total %
statement 26 29 89.6
branch 12 14 85.7
condition 4 9 44.4
subroutine 5 6 83.3
pod 4 4 100.0
total 51 62 82.2


line stmt bran cond sub pod time code
1             package Unicode::Map8;
2              
3             # Copyright 1998, Gisle Aas.
4             #
5             # This library is free software; you can redistribute it and/or
6             # modify it under the same terms as Perl itself.
7              
8 4     4   3115 use strict;
  4         9  
  4         166  
9 4     4   20 use vars qw($VERSION @ISA @EXPORT_OK $DEBUG $MAPS_DIR %ALIASES);
  4         7  
  4         3240  
10              
11             require DynaLoader;
12             @ISA=qw(DynaLoader);
13              
14             require Exporter;
15             *import = \&Exporter::import;
16             @EXPORT_OK = qw(NOCHAR MAP8_BINFILE_MAGIC_HI MAP8_BINFILE_MAGIC_LO);
17              
18             $VERSION = '0.13';
19             #$DEBUG++;
20              
21             bootstrap Unicode::Map8 $VERSION;
22              
23             #$MAPS_DIR; # where to locate map files
24             #%ALIASES; # alias names
25              
26             # Try to locate the maps directory, and read the aliases file
27             for (split(':', $ENV{MAPS_PATH} || ""),
28             (map "$_/Unicode/Map8/maps", @INC),
29             "."
30             )
31             {
32             if (open(ALIASES, "$_/aliases")) {
33             $MAPS_DIR = $_;
34             local($_);
35             while () {
36             next if /^\s*\#/;
37             chomp;
38             my($charset, @aliases) = split(' ', $_);
39             next unless $charset;
40             my $alias;
41             for $alias (@aliases) {
42             $ALIASES{$alias} = $charset;
43             }
44             }
45             close(ALIASES);
46             last;
47             }
48             }
49             $MAPS_DIR ||= ".";
50              
51             sub new
52             {
53 8     8 1 5380 my $class = shift;
54 8         16 my $self;
55 8 100       30 if (@_) {
56 7         16 my $file = shift;
57 7 100       28 $file = $file->{ID} if ref($file); # Unicode::Map compatibility
58              
59 7 50       47 if ($file =~ /\.bin$/) {
    100          
60 0         0 $self = Unicode::Map8::_new_binfile($file);
61             } elsif ($file =~ /\.txt$/) {
62 1         69 $self = Unicode::Map8::_new_txtfile($file);
63             } else {
64 6   66     39 my $charset = $ALIASES{$file} || $file;
65 6         22 $file = "$MAPS_DIR/$charset";
66 6   33     741 $self = Unicode::Map8::_new_binfile("$file.bin") ||
67             Unicode::Map8::_new_txtfile("$file.txt") ||
68             Unicode::Map8::_new_binfile("$file") ||
69             Unicode::Map8::_new_txtfile("$file");
70 6 100       35 $self->{'charset'} = $charset if $self;
71             }
72             } else {
73 1         7 $self = Unicode::Map8::_new();
74             }
75 8 100       32 bless $self, $class if $self;
76 8 50 33     28 print "CREATED $self\n" if $DEBUG && $self;
77 8         25 $self;
78             }
79              
80             sub tou
81             {
82 1     1 1 1265 require Unicode::String;
83 1         4384 my $self = shift;
84 1         18 Unicode::String::utf16($self->to16(@_));
85             }
86              
87             sub unmapped_to8
88             {
89 0     0 1 0 my($self, $code) = @_;
90 0         0 "";
91             }
92              
93             sub unmapped_to16
94             {
95 5     5 1 7045 my($self, $code) = @_;
96 5         18 "";
97             }
98              
99             # Some Unicode::Map compatibility stuff
100              
101             *from_unicode = \&to8;
102             *to_unicode = \&to16;
103              
104             1;
105              
106             __END__