| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::Translit::String; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 4 |  |  | 4 |  | 77253 | use strict; | 
|  | 4 |  |  |  |  | 27 |  | 
|  | 4 |  |  |  |  | 115 |  | 
| 4 | 4 |  |  | 4 |  | 23 | use warnings; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 97 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 4 |  |  | 4 |  | 2188 | use English; | 
|  | 4 |  |  |  |  | 15463 |  | 
|  | 4 |  |  |  |  | 24 |  | 
| 7 | 4 |  |  | 4 |  | 3694 | use Error::Pure qw(err); | 
|  | 4 |  |  |  |  | 30399 |  | 
|  | 4 |  |  |  |  | 86 |  | 
| 8 | 4 |  |  | 4 |  | 9182 | use Getopt::Std; | 
|  | 4 |  |  |  |  | 213 |  | 
|  | 4 |  |  |  |  | 231 |  | 
| 9 | 4 |  |  | 4 |  | 2001 | use Lingua::Translit; | 
|  | 4 |  |  |  |  | 152810 |  | 
|  | 4 |  |  |  |  | 1388 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | our $VERSION = 0.09; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | # Constructor. | 
| 14 |  |  |  |  |  |  | sub new { | 
| 15 | 6 |  |  | 6 | 1 | 7496 | my $class = shift; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | # Create object. | 
| 18 | 6 |  |  |  |  | 15 | my $self = bless {}, $class; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | # Object. | 
| 21 | 6 |  |  |  |  | 24 | return $self; | 
| 22 |  |  |  |  |  |  | } | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | # Run script. | 
| 25 |  |  |  |  |  |  | sub run { | 
| 26 | 5 |  |  | 5 | 1 | 8 | my $self = shift; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | # Process arguments. | 
| 29 | 5 |  |  |  |  | 25 | $self->{'_opts'} = { | 
| 30 |  |  |  |  |  |  | 'h' => 0, | 
| 31 |  |  |  |  |  |  | 'r' => 0, | 
| 32 |  |  |  |  |  |  | 't' => 'ISO 9', | 
| 33 |  |  |  |  |  |  | }; | 
| 34 | 5 | 100 | 100 |  |  | 21 | if (! getopts('hrt:', $self->{'_opts'}) || @ARGV < 1 | 
|  |  |  | 66 |  |  |  |  | 
| 35 |  |  |  |  |  |  | || $self->{'_opts'}->{'h'}) { | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 2 |  |  |  |  | 163 | print STDERR "Usage: $0 [-h] [-r] [-t table] [--version]\n\t". | 
| 38 |  |  |  |  |  |  | "string\n\n"; | 
| 39 | 2 |  |  |  |  | 25 | print STDERR "\t-h\t\tPrint help.\n"; | 
| 40 | 2 |  |  |  |  | 21 | print STDERR "\t-r\t\tReverse transliteration.\n"; | 
| 41 | 2 |  |  |  |  | 21 | print STDERR "\t-t table\tTransliteration table (default ". | 
| 42 |  |  |  |  |  |  | "value is 'ISO 9').\n"; | 
| 43 | 2 |  |  |  |  | 21 | print STDERR "\t--version\tPrint version.\n"; | 
| 44 | 2 |  |  |  |  | 9 | return 1; | 
| 45 |  |  |  |  |  |  | } | 
| 46 | 3 |  |  |  |  | 159 | $self->{'_string'} = $ARGV[0]; | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | # Run. | 
| 49 | 3 |  |  |  |  | 7 | my $ret; | 
| 50 | 3 |  |  |  |  | 23 | eval { | 
| 51 | 3 |  |  |  |  | 19 | my $tr = Lingua::Translit->new($self->{'_opts'}->{'t'}); | 
| 52 | 3 | 100 |  |  |  | 1948 | if ($self->{'_opts'}->{'r'}) { | 
| 53 | 2 | 100 |  |  |  | 8 | if ($tr->can_reverse) { | 
| 54 |  |  |  |  |  |  | $ret = $tr->translit_reverse( | 
| 55 | 1 |  |  |  |  | 18 | $self->{'_string'}); | 
| 56 |  |  |  |  |  |  | } else { | 
| 57 | 1 |  |  |  |  | 9 | err 'No reverse transliteration.'; | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  | } else { | 
| 60 | 1 |  |  |  |  | 6 | $ret = $tr->translit($self->{'_string'}); | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  | }; | 
| 63 | 3 | 100 |  |  |  | 38960 | if ($EVAL_ERROR) { | 
| 64 | 1 |  |  |  |  | 5 | err 'Cannot transliterate string.', | 
| 65 |  |  |  |  |  |  | 'Error', $EVAL_ERROR; | 
| 66 |  |  |  |  |  |  | } | 
| 67 | 2 |  |  |  |  | 77 | print "$ret\n"; | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 2 |  |  |  |  | 11 | return 0; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | 1; | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | __END__ |