1 # This module is part of , 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: Reference.pm 44 2013-09-10 00:37:13Z don $
11 Reference -- Reference superclass
27 use vars qw($VERSION $REVISION $DEBUG);
33 ($REVISION) = q$LastChangedRevision: 44 $ =~ /\$LastChangedRevision:\s+([^\s+])/;
34 $DEBUG = 0 unless defined $DEBUG;
42 my $reference = new Reference;
45 Creates a new reference object
52 $class = ref $class if ref $class;
66 @$self->{ref_fields}{$self->ref_fields} = (1) x $self->ref_fields;
68 Returns the fields that this reference knows how to deal with (or that
69 should be dealt with using ref_fields).
71 This default implementation returns an empty list, and as such should
72 be overriden by all Reference::Type subclasses.
85 $reference->ref_field('author',['John Q. Smith', 'Randal P. Swag']);
87 Sets the reference field to the passed value (if any) and returns the
88 new value. This function is called through AUTOLOAD using the
89 $reference->field() syntax.
91 Returns the new setting of passed field.
93 Scalar fieldname, and an optional scalar, arrayref, or hashref to set
99 my ($self,$field_name,$field_value) = @_;
101 if ($self->{ref_fields}->{lc($field_name)}) {
102 # Check to make sure that only 3 arguments are passed to
103 # avoid triggering on the Params::Variable style of calling.
104 # XXX We should check explicitly for this. [See Author.pm]
105 if (defined $field_value and scalar(@_) == 3) {
106 $self->{reference}->{lc($field_name)} = $field_value;
108 return $self->{reference}->{lc($field_name)};
110 carp "Invalid field name $field_name";
116 Dispatches calls to $reference->fieldname to
117 $reference->ref_field('fieldname').
119 XXX I really wish there was a way to tell perl that we don't want to
120 XXX handle a call to AUTOLOAD.
125 my $function = $AUTOLOAD;
126 ($function) = $function =~ /\:?([^\:]+)$/;
128 if (ref $self and $self->{ref_fields}->{lc($function)}) {
129 # slap $self and $function into @_.
130 unshift @_, ($self,$function);
134 croak "Undefined subroutine $function";
147 Class::Modular->can('METHOD');
149 Replaces UNIVERSAL's can method so that handled methods are reported
150 correctly. Calls UNIVERSAL::can in the places where we don't know
153 Returns a coderef to the method if the method is supported, undef
159 my ($self,$method,$vars) = @_;
161 my $universal_can = UNIVERSAL::can($self,$method);
164 return $universal_can;
166 elsif (ref $self and exists $self->{ref_fields}->{lc($method)}) {
167 # If there is no other method for dealing with this method,
168 # and we would normally autoload it, create an anonymous sub
169 # to deal with it appropriately.
170 return sub{my $self = shift; return $self->ref_field($method,@_);};
187 # ref_fields is used by AUTOLOAD to know when it's ok to set a
189 my @ref_fields = $self->ref_fields;
190 @{$self->{ref_fields}}{@ref_fields} = (1) x scalar @ref_fields;
197 # From http://www.ecst.csuchico.edu/~jacobsd/bib/formats/
201 # * MARC [MARC::Record]
202 # * Melvyl [Uses MARC]
210 # * Computing Archives
211 # * Uniform Resource Citation
212 # * RFC 1807 (replaces RFC 1357)