| 1 | package MARC::Detrans::Rule; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 9 | ▶ | use Carp qw( croak ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | MARC::Detrans::Rule | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | use MARC::Detrans::Rule; | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | my $rule = MARC::Detrans::Rule->new( | ||||||||||||||||||||
| 16 | from => 'b', | ||||||||||||||||||||
| 17 | to => 'B', | ||||||||||||||||||||
| 18 | escape => '(B' | ||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | It's unlikely that you'll want to use MARC::Detrans::Rule directly since | ||||||||||||||||||||
| 24 | other modules wrap access to it. Each detransliteration rule is represented | ||||||||||||||||||||
| 25 | as a MARC::Detrans::Rule object, which basically provides the Romanized text | ||||||||||||||||||||
| 26 | and the corresponding MARC-8 or UTF-8 text, along with an escape character | ||||||||||||||||||||
| 27 | (for MARC-8) rules. | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =head1 METHODS | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | =head2 new() | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | Pass in the C<from> and c<to> parameters which define the original text | ||||||||||||||||||||
| 34 | and what to translate to; these parameters are not limited to single | ||||||||||||||||||||
| 35 | characters. In addition an C<escape> parameter can be passed in to | ||||||||||||||||||||
| 36 | indicate a MARC-8 escape sequence to use. Also a C<position> parameter | ||||||||||||||||||||
| 37 | can be set to C<initial>, C<medial> or C<final> if the rule applies only | ||||||||||||||||||||
| 38 | when the character is found at or within a particular word boundary. | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 465 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||
| 43 | 465 | my ( $class, %opts ) = @_; | |||||||||||||||||||
| 44 | 465 | ▶ | croak( "must supply 'from' parameter" ) if ! exists( $opts{from} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 465 | ▶ | croak( "must supply 'to' parameter" ) if ! exists( $opts{to} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 465 | $opts{to} =~ s/\^ESC/\x1B/g; | |||||||||||||||||||
| 47 | 465 | ▶ | return bless \%opts, ref($class) || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | =head2 from() | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | Returns the Romanized text that this rule refers to. | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 3711 | ▶ | sub from { | ||||||||||||||||||
|
Subroutine
from: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 57 | 3711 | return shift->{from}; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =head2 to() | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | Returns the MARC-8 or UTF-8 text that the corresponding Romanized text should | ||||||||||||||||||||
| 63 | be converted to. | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 1115 | ▶ | sub to { | ||||||||||||||||||
|
Subroutine
to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 68 | 1115 | return shift->{to}; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =head2 escape() | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | Returns a MARC-8 character set escape sequence to be used, or undef if the rule | ||||||||||||||||||||
| 74 | is for an UTF-8 mapping. | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 2365 | ▶ | sub escape { | ||||||||||||||||||
|
Subroutine
escape: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 79 | 2365 | return shift->{escape}; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | =head2 position() | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | Returns a position specification for the rule mapping which can be | ||||||||||||||||||||
| 85 | initial, medial, final or the empty string if there is no positional | ||||||||||||||||||||
| 86 | qualification for the rule. | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 1746 | ▶ | sub position { | ||||||||||||||||||
|
Subroutine
position: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 91 | 1746 | my $p = shift->{position}; | |||||||||||||||||||
| 92 | 1746 | ▶ | return $p if defined($p); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 1696 | return ''; | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =head1 AUTHORS | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =over 4 | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =item * Ed Summers <ehs@pobox.com> | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | =back | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 9 | 1; | |||||||||||||||||||