Detrans/Names.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 2 / 2 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 3 / 3 totaltotal 90.7% 39 / 43 CC 4 SCAR 7.0
CC
4
Cov
94%
addName
3.0
new
2.1
BEGIN
1.0
CRAP 2.0
« Detrans/Rule.pm ↑ Summary Detrans/Name.pm »
1 package MARC::Detrans::Names;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 MARC::Detrans::Names - A set of non-standard authority mappings
9  
10 =head1 SYNOPSIS
11  
12 use MARC::Detrans::Names
13 my $names = MARC::Detrans::Names->new();
14 $names->addName(
15 from => '$aNicholas $bI, $cEmperor of Russia, $d1796-1855',
16 to => '$a^[(NnIKOLAJ^[s, $bI, $c^[(NiMPERATOR^[s ^[(NwSEROSSIJSKIJ^[s, $d1796-1855'
17 );
18  
19 =head1 DESCRIPTION
20  
21 Often times personal names are transliterated in non-standard ways, so
22 in order to get back to the original script it's necessary to have
23 non-standard mappings. MARC::Detrans::Names allows you to map the
24 transliterated name back to it's original.
25  
26 =head1 METHODS
27  
28 =head2 new()
29  
30 =cut
31  
32 8 ▶sub new {
Subroutine new: called CC=2 SCAR=7.4
Pod documented
33 8 my $class = shift;
34 8 ▶ my $self = bless {}, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
080
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
35 8 $self->{storage} = {};
36 8 return $self;
37 }
38  
39 =head2 addName()
40  
41 You must pass in a MARC::Detrans::Name object that you want to have added
42 to the names mapping.
43  
44 =cut
45  
46 5 ▶sub addName {
Subroutine addName: called CC=3 SCAR=11.0
Pod documented
47 5 my ($self,$name) = @_;
48 5 my $from = $name->from();
49 5 my $to = $name->to();
50  
51 ## squash space and remove indicators
52 5 $from =~ s/ //g;
53 5 $from =~ s/\$.//g;
54  
55 ## create a list of subfield data, suitable for easily
56 ## passing to MARC::Field->new()
57 5 my @chunks = split /\$/, $to;
58 5 my @subfields = ();
59 5 foreach my $chunk ( @chunks ) {
60 ## first chunk will be empty
61 25 ▶ next if $chunk eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $chunk eq "" 5 20 25
62 20 my $subfield = substr( $chunk,0,1 );
63 20 my $data = substr( $chunk,1 );
64 20 push( @subfields, $subfield, $data );
65 }
66  
67 5 $self->{storage}{$from} = \@subfields;
68 }
69  
70 =head2 convert()
71  
72 Pass in a MARC::Field object and you'll get back an array ref of
73 modified subfield data which could be used to create a new field.
74 If there is no mapping for a particular MARC::Field then you'll get
75 back undef.
76  
77 =cut
78  
79 17 ▶sub convert {
Subroutine convert: called CC=1 SCAR=0.0
Pod documented
80 17 my ($self,$field) = @_;
81  
82 ## make the hash key
83 17 my $from = $field->as_string();
84 17 $from =~ s/ //g;
85  
86 ## do the lookup, and return
87 17 return $self->{storage}{$from};
88 }
89  
90 8 1;
« Detrans/Rule.pm ↑ Summary Detrans/Name.pm »