File Coverage

blib/lib/Text/Transliterator.pm
Criterion Covered Total %
statement 21 21 100.0
branch 5 8 62.5
condition 5 7 71.4
subroutine 3 3 100.0
pod 1 1 100.0
total 35 40 87.5


line stmt bran cond sub pod time code
1             package Text::Transliterator;
2 3     3   253661 use strict;
  3         7  
  3         111  
3 3     3   15 use warnings;
  3         12  
  3         1036  
4            
5             our $VERSION = '1.06';
6            
7             sub new {
8 5     5 1 238746 my $class = shift;
9 5         12 my ($from, $to);
10            
11             # first arguments : either a hashref, or a pair of strings
12 5 100 100     35 if ((ref $_[0] || '') eq 'HASH') {
13 3         5 my $map = shift;
14 3         127 $from = join "", keys %$map;
15 3         106 $to = join "", values %$map;
16             }
17             else {
18 2         5 $from = shift;
19 2         4 $to = shift;
20 2 50 33     13 defined $from and defined $to
21             or die 'Text::Transliterator->new($from, $to): invalid args';
22             }
23            
24             # remaining arguments
25 5   100     22 my $modifiers = shift || '';
26             not @_
27 5 50       14 or die 'Text::Transliterator->new(): too many args';
28            
29             # build the coderef.
30             # Returns the list of tr/../../ results.
31             # In scalar context, returns the last item (for compatibility with the previous API)
32 5         13 my $src = "sub {my \@l = map {tr[$from][$to]$modifiers} \@_; return wantarray ? \@l : \$l[-1]}";
33 5         8 local $@;
34 5 50       1316 my $coderef = eval $src or die "Text::Transliterator: error in compiling the tr function: $@";
35            
36 5         259 return $coderef;
37             }
38            
39            
40             1; # End of Text::Transliterator
41            
42             __END__