1 # This module is part of da_reference, and is released
2 # under the terms of the GPL version 2, or any later version. See the
3 # file README and COPYING for more information.
4 # Copyright 2003 by Don Armstrong <don@donarmstrong.com>.
5 # $Id: Journal.pm 44 2013-09-10 00:37:13Z don $
7 package Reference::Field::Journal;
27 use vars qw($REVISION $DEBUG @JOURNAL_FIELDS);
30 use Params::Validate qw(:types validate_with);
33 ($REVISION) = q$LastChangedRevision: 44 $ =~ /\$LastChangedRevision:\s+([^\s+])/;
34 $DEBUG = 0 unless defined $DEBUG;
35 @JOURNAL_FIELDS = qw(title medlineabbr isoabbr nlmid issn eissn publisher pmid);
42 $self->{reference}->{journal} = {};
43 @{$self->{reference}->{journal}}{@JOURNAL_FIELDS} = (undef) x scalar @JOURNAL_FIELDS;
52 if (scalar(@_) == 1) {
53 $params{journal} = shift;
54 $params{output} = 'scalar';
58 @spec{@JOURNAL_FIELDS} = ({type => SCALAR|UNDEF,optional=>1}) x scalar @JOURNAL_FIELDS;
59 %params = validate_with(params => \@_,
60 spec => {journal => {type => SCALAR,
63 output => {type => SCALAR,
70 # Were we called using $reference->journal(foo=>bar) {ignoring journal=>bar} ?
71 my $using_param_call = 0;
72 foreach my $key (@JOURNAL_FIELDS) {
73 $using_param_call = 1 and last if exists $params{$key} and defined $params{$key};
75 if ($using_param_call) {
76 foreach my $key (@JOURNAL_FIELDS) {
77 $self->{reference}->{journal}->{$key} = $params{$key} if exists $params{$key} and defined $params{$key};
80 elsif (defined $params{journal}) {
81 $self->{reference}->{journal}->{title} = $params{journal};
84 local $_ = $params{output};
86 my $title = $self->{reference}->{journal}->{medlineabbr} || $self->{reference}->{journal}->{title};
87 $title =~ s/[^A-Za-z0-9]//g;
90 return $self->{reference}->{journal}->{medlineabbr} || $self->{reference}->{journal}->{title};
92 return $self->{reference}->{journal}->{isoabbr} || $self->{reference}->{journal}->{title};
95 return $self->{reference}->{journal}->{title};