line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Transliterator;
|
2
|
3
|
|
|
3
|
|
136664
|
use strict;
|
|
3
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
86
|
|
3
|
3
|
|
|
3
|
|
16
|
use warnings;
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
703
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.04';
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new {
|
8
|
3
|
|
|
3
|
1
|
1454
|
my $class = shift;
|
9
|
3
|
|
|
|
|
9
|
my ($from, $to);
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# first arguments : either a hashref, or a pair of strings
|
12
|
3
|
100
|
100
|
|
|
19
|
if ((ref $_[0] || '') eq 'HASH') {
|
13
|
2
|
|
|
|
|
7
|
my $map = shift;
|
14
|
2
|
|
|
|
|
93
|
$from = join "", keys %$map;
|
15
|
2
|
|
|
|
|
84
|
$to = join "", values %$map;
|
16
|
|
|
|
|
|
|
}
|
17
|
|
|
|
|
|
|
else {
|
18
|
1
|
|
|
|
|
3
|
$from = shift;
|
19
|
1
|
|
|
|
|
2
|
$to = shift;
|
20
|
1
|
50
|
33
|
|
|
6
|
defined $from and defined $to
|
21
|
|
|
|
|
|
|
or die 'Text::Transliterator->new($from, $to): invalid args';
|
22
|
|
|
|
|
|
|
}
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# remaining arguments
|
25
|
3
|
|
50
|
|
|
17
|
my $modifiers = shift || '';
|
26
|
|
|
|
|
|
|
not @_
|
27
|
3
|
50
|
|
|
|
10
|
or die 'Text::Transliterator->new(): too many args';
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# build the coderef
|
30
|
3
|
|
|
|
|
22
|
my $src = "sub {tr[$from][$to]$modifiers for \@_ }";
|
31
|
3
|
|
|
|
|
9
|
local $@;
|
32
|
3
|
50
|
|
|
|
483
|
my $coderef = eval $src or die $@;
|
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
86
|
return $coderef;
|
35
|
|
|
|
|
|
|
}
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; # End of Text::Transliterator
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
__END__
|