blib/lib/SeeAlso/Identifier/PND.pm

filter: Statementstmt 100% 64 / 64 Branchbran 92.3% 24 / 26 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 15 / 15 Podpod 100% 9 / 9 totaltotal 96.7% 118 / 122 SCAR 28.3
CC
17
Cov
97%
valid
5.0
parse
5.0
hash
4.0
CRAP 17.0
↑ Summary Build »
1 package SeeAlso::Identifier::PND;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 BEGIN {
6 6 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶ $VERSION = '0.61';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 @ISA = qw(Exporter);
10 #Give a hoot don't pollute, do not export more than needed by default
11 6 @EXPORT = qw();
12 6 @EXPORT_OK = qw();
13 6 %EXPORT_TAGS = ();
14 }
15  
16 6 ▶use base qw( SeeAlso::Identifier::GND );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 #use Carp;
18  
19 #################### subroutine header end ####################
20  
21  
22 =head1 NAME
23  
24 SeeAlso::Identifier::PND - SeeAlso handling of PND Numbers (Personennormdatei)
25  
26  
27 =head1 SYNOPSIS
28  
29 my $pnd = new SeeAlso::Identifier::PND "";
30  
31 print "invalid/empty" unless $pnd; # $pnd is defined but false !
32  
33 $pnd->value( '101115658X' );
34 $pnd->value( 'PND:101115658X' );
35 $pnd->value( '(DE-588)101115658X' );
36 $pnd->value( '(DE-588a)101115658X' );
37 $pnd->value( 'http://d-nb.info/gnd/101115658X' );
38 $pnd->value; # '' or PND identifier again (101115658X)
39 $pnd; # PND identifier as URI (http://d-nb.info/gnd/101115658X)
40  
41 $pnd->canonical; # http://d-nb.info/gnd/101115658X
42  
43 $pnd->pretty; # '' or PND identifier again (101115658X)
44  
45 =head1 DESCRIPTION
46  
47 This module handles identification numbers of the former Personennormdatei (PND)
48 of the German National Library (DNB). These continue to be valid identification
49 numbers of the successor Gemeinsame Normdatei (GND).
50  
51 The constructor of SeeAlso::Identifier::PND always returns an defined identifier
52 with all methods provided by L<SeeAlso::Identifier>.
53 As canonical form the URN representation of PND with prefix C<http://d-nb.info/gnd>
54 is used (these HTTP URIs actually resolve).
55 As hashed and "pretty" form of an PND number, the number itself is used (including check digit).
56  
57 The authority files PND, GKD and SWD have been combined to the GND (Gemeinsame
58 Norm-Datei) in early 2012, the identifiers of "legacy" records however will
59 remain valid. They already are distinct and as such the parent module
60 L<SeeAlso::Identifier::GND> handles them simultaneously. As of v0.57
61 SeeAlso::Identifier::GND is lacking support for 10-digit identifiers and
62 does not implement all possible constraints (e.g. there are conflicting
63 checksum algorithms but by looking at the identifier you can not always
64 determine the authority file it belongs to and therefore there is no
65 certainity about the correct checksum).
66  
67 This module SeeAlso::Identifier::PND does not support the legacy GND numbers
68 for former entries of GKD and SWD and therefore its realm continues to be
69 restricted to authority records for persons and names (Tn and Tp) within
70 the GND.
71  
72 For compatibility reasons with SeeAlso::Identifier::GND the objects of this
73 module are implemented as blessed hashes instead of blessed scalars as
74 they would be by inheritance from SeeAlso::Identifier.
75  
76 =head1 METHODS
77  
78 =head2 parse ( $value )
79  
80 Get and/or set the value of the PND identifier. Returns an empty string or a possibly valid PND number. You can also use this method as function.
81  
82 Older numbers begin with "10" to "16" and have 8 digits plus check digit (which might be "X"),
83 More recently (since April 2011) assigned numbers have 9 digits plus check digit(0-X) and currently begin with "10".
84  
85 Although there is no official form known which notates PND numbers with dash(es),
86 their input is permitted, also prefixes "PND", "PND " and the likes.
87  
88 =cut
89  
90 sub parse {
91 147 ▶ local($_) = shift;
Subroutine parse: called CC=5 SCAR=16.1
Pod documented
92 147 ▶ $_ = shift if ref($_) and scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ and scalar @_ 145 2 147
Condition100%2/2
ref $_ and scalar @_
!ll
2145
MC/DC100%1/1
ref $_ and scalar @_
ref $_
Truth table100%2/2
A
A= ref $_
Aresult
00
11
93  
94 147 ▶ return "" unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 147 147
95  
96 147 s/\s+//g; # no kind of spaces makes sense in input data
97 147 s=^(?:http://d-nb.info/gnd/|[GP]ND[:/-]*\s?|\(DE-588[a]?\))([0-9xX-]+)=$1=i;
98  
99 147 s/^0+//;
100 147 tr/x-/X/d;
101  
102 147 ▶ return "" unless /^10?\d{7}[\dX]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^10?\d{7}[\dX]$/ 51 96 147
103  
104 96 return $_;
105 }
106  
107  
108 =head2 value ( [$value] )
109  
110 get/set using parse, not parent's method
111  
112 =cut
113  
114 sub value {
115 159 ▶ my($self, $value) = @_;
Subroutine value: called CC=2 SCAR=6.9
Pod documented
116 159 ▶ $self->{value} = $self->parse($value) if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 143 16 159
117 159 return $self->{value};
118 }
119  
120  
121 =head2 valid
122  
123 Performs checksum calculation for already parsed PND numbers.
124  
125 The mod-11-checksum is constructed the same way as for the "PICA PPN" (Pica Production Number
126 of the German National Library (PND identifiers acutally are PICA PPNs).
127  
128 =cut
129  
130 sub valid {
131 209 ▶ return undef unless $_[0]->{value} and $_[0]->{value} =~ /^10?\d{7}[\dX]$/;
Subroutine valid: called CC=5 SCAR=16.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"value"} and $_[0]{"value"} =~ /^10?\d{7}[\dX]$/ 27 182 209
Condition66%2/3
$_[0]{"value"} and $_[0]{"value"} =~ /^10?\d{7}[\dX]$/
!ll&&!rl&&r
270182
MC/DC50%1/2
$_[0]{"value"} and $_[0]{"value"} =~ /^10?\d{7}[\dX]$/
$_[0]{"value"} $_[0]{"value"} =~ /^10?\d{7}[\dX]$/
Truth table66%2/3
A and B
A= $_[0]{"value"}B= $_[0]{"value"} =~ /^10?\d{7}[\dX]$/
ABresult
0X0
100
111
132 182 my @i = reverse split(//, $_[0]->{value});
133 182 ▶ $i[0] = 10 if $i[0] =~ /X/i;
Branch: 1 branch
BranchTrueFalseTotal
if $i[0] =~ /X/i 30 152 182
134  
135 182 my ($z, $w) = (0, 1);
136 182 foreach ( @i ) {
137 1677 $z += ($_ * $w++)};
138 182 return ($z % 11) == 0;
139 }
140  
141  
142 =head2 hash ( [$value] )
143  
144 Sets and/or gets a form of the identifier suitable for processing.
145 In this class this will yield the same form as "parse", provided
146 it passes the "valid" test(s).
147  
148 =cut
149  
150 sub hash {
151 74 ▶ my $self = shift @_;
Subroutine hash: called CC=4 SCAR=13.9
Pod documented
152 74 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 48 26 74
153 48 ▶ if ( $_[0] =~ /^10?\d{7}[\dXx]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^10?\d{7}[\dXx]$/) { } 20 28 48
154 20 $self->value($_[0])}
155 else {
156 28 return $self->{value} = undef}
157 }
158 46 ▶ return $self->valid ? $self->{value} : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->valid ? : 33 13 46
159 }
160  
161  
162 =head2 indexed ( [$value] )
163  
164 This is only since the parent class L<SeeAlso::Identifier::GND> as of v0.57
165 is not compliant to the interfaces specified by L<SeeAlso::Identifier>
166 with respect to "indexed" being an alias for "hash".
167  
168 =cut
169  
170 sub indexed {
171 8 ▶ my $self = shift @_;
Subroutine indexed: called CC=1 SCAR=0.0
Pod documented
172 8 return $self->hash;
173 }
174  
175  
176 =head2 canonical ( [$value] )
177  
178 Yields the (for SeeAlso) canonical form of the identifier (if valid) as
179 an URI.
180  
181 =cut
182  
183 sub canonical {
184 126 ▶ my $self = shift @_;
Subroutine canonical: called CC=4 SCAR=13.9
Pod documented
185 126 ▶ if ( defined $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 50 76 126
186 50 ▶ if ( $_[0] =~ m=^http://d-nb.info/gnd/= ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ m[^http://d-nb.info/gnd/]) { } 42 8 50
187 42 $self->value($_[0])}
188 else {
189 8 return $self->{value} = undef}
190 }
191 118 ▶ return $self->valid ? ("http://d-nb.info/gnd/" . $self->{value}) : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->valid ? : 83 35 118
192 }
193  
194  
195 =head2 normalized ( [$value] )
196  
197 This is only since the parent class L<SeeAlso::Identifier::GND> as of v0.57
198 is not compliant to the interfaces specified by L<SeeAlso::Identifier>
199 with respect to "normalized" being an alias for "canonical".
200  
201 =cut
202  
203 sub normalized {
204 8 ▶ my $self = shift @_;
Subroutine normalized: called CC=1 SCAR=0.0
Pod documented
205 8 return $self->canonical;
206 }
207  
208  
209 =head2 cmp ( $value )
210  
211 For comparisons a "numerical" order is established by left-padding
212 the identifiers with sufficiently many zeroes.
213  
214 =cut
215  
216 sub cmp {
217 11 ▶ my $self = shift;
Subroutine cmp: called CC=1 SCAR=0.0
Pod documented
218 11 my $string1 = sprintf("%010s", $self->{value});
219 11 my $class = ref($self);
220 11 my $second = shift;
221 11 my $string2 = sprintf("%010s", $class->new($second)->{value});
222 11 return $string1 cmp $string2;
223 }
224  
225  
226 =head2 pretty
227  
228 Try to give the most official form of the identifier.
229  
230 =cut
231  
232 sub pretty {
233 10 ▶ my $self = shift @_;
Subroutine pretty: called CC=2 SCAR=7.2
Pod documented
234 10 ▶ return $self->valid ? $self->{value} : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->valid ? : 10 0 10
235 }
236  
237  
238 =head1 AUTHOR
239  
240 Thomas Berger C<< <THB@gymel.com> >>
241  
242 =head1 ACKNOWLEDGEMENTS
243  
244 Jakob Voss C<< <jakob.voss@gbv.de> >> crafted SeeAlso::Identifier::GND.
245  
246 =head1 COPYRIGHT
247  
248 This program is free software; you can redistribute
249 it and/or modify it under the same terms as Perl itself.
250  
251 The full text of the license can be found in the
252 LICENSE file included with this module.
253  
254  
255 =head1 SEE ALSO
256  
257 perl(1), L<SeeAlso::Identifer::GND>.
258  
259 =cut
260  
261 #################### main pod documentation end ###################
262  
263  
264 6 1;
265 # The preceding line will help the module return a true value
266  
↑ Summary Build »