line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MARC::SubjectMap::Rule; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
10602
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
224
|
|
4
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
161
|
|
5
|
5
|
|
|
5
|
|
27
|
use base qw( Class::Accessor ); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
5147
|
|
6
|
5
|
|
|
5
|
|
12865
|
use MARC::SubjectMap::XML qw( element startTag endTag ); |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
3054
|
|
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
|
|
|
|
|
|
|
sub new { |
27
|
1
|
|
|
1
|
1
|
477
|
my ($class,$parms) = @_; |
28
|
1
|
50
|
|
|
|
9
|
$parms->{original} = _normalize($parms->{original}) |
29
|
|
|
|
|
|
|
if exists $parms->{original}; |
30
|
1
|
|
|
|
|
10
|
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
|
|
|
|
|
|
|
my @fields = qw( field subfield source ); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( @fields ); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub original { |
50
|
2
|
|
|
2
|
1
|
767
|
my ($self,$text) = @_; |
51
|
2
|
50
|
|
|
|
10
|
if ( defined $text ) { |
52
|
0
|
|
|
|
|
0
|
$self->{original} = _normalize($text); |
53
|
|
|
|
|
|
|
} |
54
|
2
|
|
|
|
|
11
|
return $self->{original}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub translation { |
58
|
2
|
|
|
2
|
1
|
5
|
my ($self,$text) = @_; |
59
|
2
|
50
|
|
|
|
7
|
if ( defined $text ) { |
60
|
0
|
|
|
|
|
0
|
$self->{translation} = _normalize($text); |
61
|
|
|
|
|
|
|
} |
62
|
2
|
|
|
|
|
7
|
return $self->{translation}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _normalize { |
66
|
1
|
|
|
1
|
|
3
|
my $text = shift; |
67
|
1
|
50
|
|
|
|
4
|
return unless defined $text; |
68
|
1
|
|
|
|
|
5
|
$text =~ s/\.$//; |
69
|
1
|
|
|
|
|
3
|
$text =~ s/ +$//; |
70
|
1
|
|
|
|
|
3
|
return $text; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub toString { |
74
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
75
|
0
|
|
|
|
|
0
|
my @chunks = (); |
76
|
0
|
|
|
|
|
0
|
foreach my $field ( @fields ) { |
77
|
0
|
0
|
|
|
|
0
|
push( @chunks, "$field: " . exists($self->{$field}) ? |
78
|
|
|
|
|
|
|
$self->{field} : "" ); |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
0
|
return join( "; ", @chunks ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub toXML { |
84
|
1
|
|
|
1
|
0
|
363
|
my $self = shift; |
85
|
1
|
|
|
|
|
5
|
my $xml = startTag( "rule", field => $self->field(), |
86
|
|
|
|
|
|
|
subfield => $self->subfield() ) . "\n"; |
87
|
1
|
|
|
|
|
16
|
$xml .= element( "original", $self->original() ) . "\n"; |
88
|
1
|
|
|
|
|
3
|
$xml .= element( "translation", $self->translation() ) . "\n"; |
89
|
1
|
|
|
|
|
4
|
$xml .= element( "source", $self->source() ) . "\n"; |
90
|
1
|
|
|
|
|
3
|
$xml .= endTag( "rule" ) . "\n"; |
91
|
1
|
|
|
|
|
22
|
return $xml; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|