| 1 | package MARC::SubjectMap::Rule; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 5 | ▶ | use base qw( Class::Accessor ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use MARC::SubjectMap::XML qw( element startTag endTag ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | MARC::SubjectMap::Rule - a transformation rule | ||||||||||
| 11 | |||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||
| 13 | |||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||
| 15 | |||||||||||
| 16 | =head1 METHODS | ||||||||||
| 17 | |||||||||||
| 18 | =head1 new() | ||||||||||
| 19 | |||||||||||
| 20 | The constructor which can be passed a hash of values to ues in the | ||||||||||
| 21 | new object. Valid keys are field, subfield, original, translation | ||||||||||
| 22 | and source. | ||||||||||
| 23 | |||||||||||
| 24 | =cut | ||||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 27 | 1 | my ($class,$parms) = @_; | |||||||||
| 28 | $parms->{original} = _normalize($parms->{original}) | ||||||||||
| 29 | 1 | ▶ | if exists $parms->{original}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 1 | return $class->SUPER::new($parms); | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | =head2 field() | ||||||||||
| 34 | |||||||||||
| 35 | =head2 subfield() | ||||||||||
| 36 | |||||||||||
| 37 | =head2 original() | ||||||||||
| 38 | |||||||||||
| 39 | =head2 translation() | ||||||||||
| 40 | |||||||||||
| 41 | =head2 source() | ||||||||||
| 42 | |||||||||||
| 43 | =cut | ||||||||||
| 44 | |||||||||||
| 45 | 5 | my @fields = qw( field subfield source ); | |||||||||
| 46 | |||||||||||
| 47 | 5 | __PACKAGE__->mk_accessors( @fields ); | |||||||||
| 48 | |||||||||||
| 49 | 2 | ▶ | sub original { | ||||||||
|
Subroutine
original: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||
| 50 | 2 | my ($self,$text) = @_; | |||||||||
| 51 | 2 | ▶ | if ( defined $text ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | $self->{original} = _normalize($text); | |||||||||
| 53 | } | ||||||||||
| 54 | 2 | return $self->{original}; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 2 | ▶ | sub translation { | ||||||||
|
Subroutine
translation: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||
| 58 | 2 | my ($self,$text) = @_; | |||||||||
| 59 | 2 | ▶ | if ( defined $text ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | $self->{translation} = _normalize($text); | |||||||||
| 61 | } | ||||||||||
| 62 | 2 | return $self->{translation}; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 1 | ▶ | sub _normalize { | ||||||||
|
Subroutine
_normalize: called CC=2 SCAR=7.0
| |||||||||||
| 66 | 1 | my $text = shift; | |||||||||
| 67 | 1 | ▶ | return unless defined $text; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 1 | $text =~ s/\.$//; | |||||||||
| 69 | 1 | $text =~ s/ +$//; | |||||||||
| 70 | 1 | return $text; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 0 | ▶ | sub toString { | ||||||||
|
Subroutine
toString: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 74 | 0 | my $self = shift; | |||||||||
| 75 | 0 | my @chunks = (); | |||||||||
| 76 | 0 | foreach my $field ( @fields ) { | |||||||||
| 77 | push( @chunks, "$field: " . exists($self->{$field}) ? | ||||||||||
| 78 | 0 | ▶ | $self->{field} : "" ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | } | ||||||||||
| 80 | 0 | return join( "; ", @chunks ); | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 1 | ▶ | sub toXML { | ||||||||
|
Subroutine
toXML: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 84 | 1 | my $self = shift; | |||||||||
| 85 | 1 | my $xml = startTag( "rule", field => $self->field(), | |||||||||
| 86 | subfield => $self->subfield() ) . "\n"; | ||||||||||
| 87 | 1 | $xml .= element( "original", $self->original() ) . "\n"; | |||||||||
| 88 | 1 | $xml .= element( "translation", $self->translation() ) . "\n"; | |||||||||
| 89 | 1 | $xml .= element( "source", $self->source() ) . "\n"; | |||||||||
| 90 | 1 | $xml .= endTag( "rule" ) . "\n"; | |||||||||
| 91 | 1 | return $xml; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 5 | 1; | |||||||||
| 95 | |||||||||||