SubjectMap/Field.pm

filter: Statementstmt 98.4% 63 / 64 Branchbran 65.6% 21 / 32 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 14 / 14 Podpod 90.0% 9 / 10 totaltotal 86.4% 108 / 125 CC 18 SCAR 14.5
CC
18
Cov
86%
new
10.4
toXML
3.0
addTranslate
3.0
CRAP 4.3
« SubjectMap/Handler.pm ↑ Summary SubjectMap/Rule.pm »
1 package MARC::SubjectMap::Field;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use MARC::SubjectMap::XML qw( startTag endTag element emptyElement );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 MARC::SubjectMap::Field - represent field/subfield combinations to examine
11  
12 =head1 SYNOPSIS
13  
14 =head1 DESCRIPTION
15  
16 The MARC::SubjectMap configuration includes information about which
17 field/subfield combinations to examine. This is contained in the configuration
18 as a list of MARC::SubjectMap::Field objects which individually bundle up the
19 information.
20  
21 =head1 METHODS
22  
23 =head2 new()
24  
25 The constructor. Optionally you can supply tag, translate and copy during the
26 constructor call instead of using the setters.
27  
28 my $f = MARC::Subject::Field->new( { tag => '650', copy => ['a','b'] } )
29  
30 =cut
31  
32 1 ▶sub new {
Subroutine new: called CC=8 SCAR=23.4
Pod documented
33 1 my ( $class, $args ) = @_;
34 1 ▶ $args = {} unless ref($args) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args eq "HASH" 1 0 1
35 1 ▶ my $self = bless $args, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
36 # set up defaults
37 1 ▶ $self->{translate} = [] unless exists $self->{translate};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"translate"} 1 0 1
38 1 ▶ $self->{copy} = [] unless exists $self->{copy};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"copy"} 1 0 1
39 1 ▶ $self->{sourceSubfield} = 'a' unless exists $self->{sourceSubfield};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"sourceSubfield"} 1 0 1
40 1 ▶ $self->{indicator1} = undef unless exists $self->{indicator1};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"indicator1"} 1 0 1
41 1 ▶ $self->{indicator2} = undef unless exists $self->{indicator2};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"indicator2"} 1 0 1
42 1 return $self;
43 }
44  
45 =head2 tag()
46  
47 Returns the tag for the field, for example: 600 or 650.
48  
49 =cut
50  
51 3 ▶sub tag {
Subroutine tag: called CC=2 SCAR=6.9
Pod documented
52 3 my ($self,$tag) = @_;
53 3 ▶ if ($tag) { $self->{tag} = $tag };
Branch: 1 branch
BranchTrueFalseTotal
if ($tag) 1 2 3
54 3 return $self->{tag};
55 }
56  
57 =head2 translate()
58  
59 Gets a list of subfields to translate in the field.
60  
61 =cut
62  
63 5 ▶sub translate {
Subroutine translate: called CC=1 SCAR=0.0
Pod documented
64 5 return @{ shift->{translate} };
65 }
66  
67 =head2 addTranslate()
68  
69 Adds a subfield to translate.
70  
71 =cut
72  
73 3 ▶sub addTranslate {
Subroutine addTranslate: called CC=3 SCAR=11.0
Pod documented
74 3 my ($self,$subfield) = @_;
75 croak( "can't both translate and copy subfield $subfield" )
76 3 ▶ if grep { $subfield eq $_ } $self->copy();
Branch: 1 branch
BranchTrueFalseTotal
if grep {$subfield eq $_;} $self->copy 1 2 3
77 2 ▶ push( @{ $self->{translate} }, $subfield ) if defined($subfield);
Branch: 1 branch
BranchTrueFalseTotal
if defined $subfield 2 0 2
78 }
79  
80 =head2 copy()
81  
82 Gets a list of subfields to copy in the field.
83  
84 =cut
85  
86 5 ▶sub copy {
Subroutine copy: called CC=1 SCAR=0.0
Pod documented
87 5 return @{ shift->{copy} };
88 }
89  
90 =head2 addCopy()
91  
92 Adds a subfield to copy.
93  
94 =cut
95  
96 3 ▶sub addCopy {
Subroutine addCopy: called CC=3 SCAR=11.0
Pod documented
97 3 my ($self,$subfield) = @_;
98 croak( "can't both copy and translate subfield $subfield" )
99 3 ▶ if grep { $subfield eq $_ } $self->translate();
Branch: 1 branch
BranchTrueFalseTotal
if grep {$subfield eq $_;} $self->translate 1 2 3
100 2 ▶ push( @{ $self->{copy} }, $subfield ) if defined($subfield);
Branch: 1 branch
BranchTrueFalseTotal
if defined $subfield 2 0 2
101 }
102  
103 =head2 sourceSubfield()
104  
105 When a new subfield is constructed for this field the $2 or source for
106 the heading will be determined by the source for a particular subfield
107 rule that was used when building the new field. Since subfield components
108 could potentially have different sources sourceSubfield() lets you
109 specify which subfield to pull the source from. If unspecified sourceSubfield()
110 will always return 'a'.
111  
112 =cut
113  
114 1 ▶sub sourceSubfield {
Subroutine sourceSubfield: called CC=2 SCAR=7.6
Pod documented
115 1 my ($self,$subfield) = @_;
116 0 ▶ if ($subfield) { $self->{sourceSubfield} = $subfield };
Branch: 1 branch
BranchTrueFalseTotal
if ($subfield) 0 1 1
117 1 return $self->{sourceSubfield};
118 }
119  
120 =head2 indicator1()
121  
122 Specify a value to limit by for the 1st indicator. Using this will mean
123 that *only* fields with 1st indicator of this value will get processed.
124 By default records will not be limited if this value is unspecified.
125  
126 =head2 indicator2()
127  
128 Same as indicator1() but for the 2nd indicator.
129  
130 =cut
131  
132 4 ▶sub indicator1 {
Subroutine indicator1: called CC=2 SCAR=6.9
Pod documented
133 4 my ($self,$indicator) = @_;
134 4 ▶ if ( defined $indicator) { $self->{indicator1} = $indicator };
Branch: 1 branch
BranchTrueFalseTotal
if (defined $indicator) 1 3 4
135 4 return $self->{indicator1};
136 }
137  
138 4 ▶sub indicator2 {
Subroutine indicator2: called CC=2 SCAR=6.9
Pod documented
139 4 my ($self,$indicator) = @_;
140 4 ▶ if ( defined $indicator) { $self->{indicator2} = $indicator };
Branch: 1 branch
BranchTrueFalseTotal
if (defined $indicator) 1 3 4
141 4 return $self->{indicator2};
142 }
143  
144 1 ▶sub toXML {
Subroutine toXML: called CC=3 SCAR=11.0
Pod undocumented
145 1 my $self = shift;
146  
147 # get the attrs into an array with defined order (instead of hash)
148 1 my @attrs = ( tag => $self->tag() );
149 1 ▶ push( @attrs, indicator1 => $self->indicator1() )
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->indicator1 1 0 1
150 if defined $self->indicator1();
151 1 ▶ push( @attrs, indicator2 => $self->indicator2() )
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->indicator2 1 0 1
152 if defined $self->indicator2();
153  
154 1 my $xml = startTag( "field", @attrs )."\n";
155 1 map { $xml .= element("copy",$_)."\n" } $self->copy();
156 1 map { $xml .= element("translate",$_)."\n" } $self->translate();
157 1 $xml .= element("sourceSubfield", $self->sourceSubfield()) . "\n";
158 1 $xml .= endTag("field")."\n";
159 1 return $xml;
160 }
161  
162 3 1;
« SubjectMap/Handler.pm ↑ Summary SubjectMap/Rule.pm »