line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SeeAlso::Identifier::ISSN; |
2
|
5
|
|
|
5
|
|
121888
|
use strict; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
197
|
|
3
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
212
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
BEGIN { |
6
|
5
|
|
|
5
|
|
24
|
use Exporter (); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
139
|
|
7
|
5
|
|
|
5
|
|
28
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
5
|
|
|
|
|
23
|
|
|
5
|
|
|
|
|
1044
|
|
8
|
5
|
|
|
5
|
|
11
|
$VERSION = '0.5704'; |
9
|
5
|
|
|
|
|
72
|
@ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
#Give a hoot don't pollute, do not export more than needed by default |
11
|
5
|
|
|
|
|
12
|
@EXPORT = qw(); |
12
|
5
|
|
|
|
|
9
|
@EXPORT_OK = qw(); |
13
|
5
|
|
|
|
|
109
|
%EXPORT_TAGS = (); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
5
|
|
|
5
|
|
26
|
use base qw(SeeAlso::Identifier); |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
2965
|
|
17
|
5
|
|
|
5
|
|
4455
|
use Business::ISSN; |
|
5
|
|
|
|
|
10590
|
|
|
5
|
|
|
|
|
2849
|
|
18
|
|
|
|
|
|
|
#use Carp; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#################### subroutine header end #################### |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
SeeAlso::Identifier::ISSN - SeeAlso handling of International Standard Serial Numbers |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $issn = new SeeAlso::Identifier::ISSN ""; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
print "invalid" unless $issn; # $issn is defined but false ! |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$issn->value; # get value |
36
|
|
|
|
|
|
|
$issn->value( '1456-5935' ); # set value |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$issn->canonical; # urn:ISSN:1456-5935 |
39
|
|
|
|
|
|
|
$issn; # ISSN as URI (urn:ISSN:1456-5935) |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$issn->pretty; # 1456-5935 (most official form) |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$issn->hash; # long int 0 <= x <= 9.999.999 (or "") |
44
|
|
|
|
|
|
|
$issn->hash( 1456593 ); # set by hash value |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 DESCRIPTION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
This module handles International Standard Serial Numbers as identifiers |
50
|
|
|
|
|
|
|
by letting L do the real work. |
51
|
|
|
|
|
|
|
Unlike L the constructor of SeeAlso::Identifier::ISSN |
52
|
|
|
|
|
|
|
always returns an defined identifier with all methods provided by |
53
|
|
|
|
|
|
|
L. |
54
|
|
|
|
|
|
|
As canonical form the URN representation of ISSN with hyphens is used. |
55
|
|
|
|
|
|
|
As hashed form of an ISSN, a 32 Bit integer can be calculated. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Please note that (hashed) 0 is a valid value representing ISSN 0000-0000. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 METHODS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 parse ( $value ) |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Get and/or set the value of the ISSN. Returns an empty string or the valid |
65
|
|
|
|
|
|
|
ISSN with hyphens as determined by L. You can also |
66
|
|
|
|
|
|
|
use this method as function. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub parse { |
71
|
0
|
|
|
0
|
1
|
|
local($_) = shift; |
72
|
0
|
0
|
0
|
|
|
|
$_ = shift if ref($_) and scalar @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
return '' unless defined $_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $testok; |
77
|
0
|
|
|
|
|
|
eval { $testok = $_->isa('Business::ISSN'); }; |
|
0
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
unless ( $testok ) { |
79
|
0
|
|
|
|
|
|
s/^\s+//; s/\s+$//; s/\s+/ /g; # normalize-spaces() |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
s/^urn:ISSN://i; |
81
|
0
|
|
|
|
|
|
s/^ISSN\s*//i; |
82
|
0
|
|
|
|
|
|
$_ = Business::ISSN->new( $_ ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
return '' unless defined $_; |
86
|
0
|
0
|
|
|
|
|
return '' unless $_->is_valid; |
87
|
0
|
|
|
|
|
|
return $_->as_string(); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 canonical |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Returns a Uniform Resource Identifier (URI) for this ISSN (or an empty string). |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This is an URI according to RFC 3044 ("urn:ISSN:..."). |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub canonical { |
99
|
0
|
0
|
|
0
|
1
|
|
return ${$_[0]} eq '' ? '' : 'urn:ISSN:' . ${$_[0]}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 hash ( [ $value ] ) |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Returns or sets a space-efficient representation of the ISSN as integer. |
105
|
|
|
|
|
|
|
An ISSN always consists of 7 digits plus a check digit/character. |
106
|
|
|
|
|
|
|
This makes 10.000.000 possible ISSN which fit in a 32 bit (signed or |
107
|
|
|
|
|
|
|
unsigned) integer value. The integer value is calculated from the ISSN by |
108
|
|
|
|
|
|
|
removing the dash and the check digit. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub hash { |
113
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# TODO: support use as constructor and as function |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if ( scalar @_ ) { |
118
|
0
|
|
|
|
|
|
my $value = shift; |
119
|
0
|
0
|
|
|
|
|
$value = defined $value ? "$value" : ""; |
120
|
0
|
0
|
0
|
|
|
|
$value = '' if not $value =~ /^[0-9]+$/ or $value >= 9999999; |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
if ( $value eq "" ) { |
123
|
0
|
|
|
|
|
|
$$self = ''; |
124
|
0
|
|
|
|
|
|
return ''; |
125
|
|
|
|
|
|
|
} |
126
|
0
|
|
|
|
|
|
my $issn = Business::ISSN->new( sprintf("%07uX", $value)); |
127
|
0
|
|
|
|
|
|
$issn->fix_checksum; |
128
|
0
|
|
|
|
|
|
$self->value( $issn ); |
129
|
0
|
|
|
|
|
|
return $self->value; |
130
|
|
|
|
|
|
|
} else { |
131
|
0
|
|
|
|
|
|
(my $v = $$self) =~ tr/-//d; |
132
|
0
|
0
|
|
|
|
|
return (length($v) == 8) ? int(substr($v, 0, 7)) : ""; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 pretty |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Returns the standard form of an ISSN with dash and captialized check digit 'X'. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub pretty { |
143
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
144
|
0
|
0
|
|
|
|
|
my $value = Business::ISSN->new($self->value) or return ""; |
145
|
0
|
|
|
|
|
|
return $value->as_string(); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 AUTHOR |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Thomas Berger C<< >> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Jakob Voss C<< >> crafted L where |
158
|
|
|
|
|
|
|
this one is heavily derived from. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 COPYRIGHT |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Copyright (c) 2010-2011 Thomas Berger. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This program is free software; you can redistribute |
165
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
The full text of the license can be found in the |
168
|
|
|
|
|
|
|
LICENSE file included with this module. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 SEE ALSO |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
perl(1), L, L. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
#################### main pod documentation end ################### |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; |
181
|
|
|
|
|
|
|
# The preceding line will help the module return a true value |
182
|
|
|
|
|
|
|
|