line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Transliterator;
|
2
|
3
|
|
|
3
|
|
27527
|
use strict;
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
70
|
|
3
|
3
|
|
|
3
|
|
7
|
use warnings;
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
434
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.02';
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new {
|
8
|
3
|
|
|
3
|
1
|
632
|
my $class = shift;
|
9
|
3
|
|
|
|
|
4
|
my ($from, $to);
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# first arguments : either a hashref, or a pair of strings
|
12
|
3
|
100
|
100
|
|
|
16
|
if ((ref $_[0] || '') eq 'HASH') {
|
13
|
2
|
|
|
|
|
4
|
my $map = shift;
|
14
|
2
|
|
|
|
|
89
|
$from = join "", keys %$map;
|
15
|
2
|
|
|
|
|
67
|
$to = join "", values %$map;
|
16
|
|
|
|
|
|
|
}
|
17
|
|
|
|
|
|
|
else {
|
18
|
1
|
|
|
|
|
2
|
$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
|
|
|
|
9
|
or die 'Text::Transliterator->new(): too many args';
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# build the coderef
|
30
|
3
|
|
|
|
|
13
|
my $src = "sub {tr[$from][$to]$modifiers for \@_ }";
|
31
|
3
|
|
|
|
|
4
|
local $@;
|
32
|
3
|
50
|
|
|
|
555
|
my $coderef = eval $src or die $@;
|
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
93
|
return $coderef;
|
35
|
|
|
|
|
|
|
}
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; # End of Text::Transliterator
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
__END__
|