]> git.donarmstrong.com Git - reference.git/blob - blib/lib/Reference/Field/Journal.pm
ad5639a481f6360fad582420633060dfb1e9cbe5
[reference.git] / blib / lib / Reference / Field / Journal.pm
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 $
6
7 package Reference::Field::Journal;
8
9 =head1 NAME
10
11  --
12
13 =head1 SYNOPSIS
14
15
16 =head1 DESCRIPTION
17
18
19 =head1 BUGS
20
21 None known.
22
23 =cut
24
25
26 use strict;
27 use vars qw($REVISION $DEBUG @JOURNAL_FIELDS);
28
29 use NEXT;
30 use Params::Validate qw(:types validate_with);
31
32 BEGIN{
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);
36 }
37
38
39 sub _init{
40      my $self = shift;
41
42      $self->{reference}->{journal} = {};
43      @{$self->{reference}->{journal}}{@JOURNAL_FIELDS} = (undef) x scalar @JOURNAL_FIELDS;
44
45      $self->NEXT::_init;
46
47 }
48
49 sub journal{
50      my $self = shift;
51      my %params;
52      if (scalar(@_) == 1) {
53           $params{journal} = shift;
54           $params{output} = 'scalar';
55      }
56      else {
57           my %spec;
58           @spec{@JOURNAL_FIELDS} = ({type => SCALAR|UNDEF,optional=>1}) x scalar @JOURNAL_FIELDS;
59           %params = validate_with(params => \@_,
60                                   spec   => {journal     => {type     => SCALAR,
61                                                              optional => 1,
62                                                             },
63                                              output      => {type     => SCALAR,
64                                                              default  => 'scalar',
65                                                             },
66                                              %spec,
67                                             },
68                                  );
69      }
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};
74      }
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};
78           }
79      }
80      elsif (defined $params{journal}) {
81           $self->{reference}->{journal}->{title} = $params{journal};
82      }
83
84      local $_ = $params{output};
85      if (/bibtex/) {
86          my $title = $self->{reference}->{journal}->{medlineabbr} || $self->{reference}->{journal}->{title};
87          $title =~ s/\s//g;
88          return $title;
89      } elsif (/medline/) {
90          return $self->{reference}->{journal}->{medlineabbr} || $self->{reference}->{journal}->{title};
91      } elsif (/iso/) {
92          return $self->{reference}->{journal}->{isoabbr} || $self->{reference}->{journal}->{title};
93      }
94      else {
95           return $self->{reference}->{journal}->{title};
96      }
97 }
98
99
100
101 1;
102
103
104 __END__
105
106
107
108
109
110