Merge branch 'master' into topic/parent_string
[cxgn-corelibs.git] / lib / MOBY / CrossReference.pm
bloba7da2747cb7e620791904a2926c2bfa4bd60326b
1 package MOBY::CrossReference;
3 #$Id: CrossReference.pm,v 1.7 2005/09/06 20:23:40 fgibbons Exp $
4 use strict;
5 use Carp;
6 use vars qw($AUTOLOAD @ISA);
8 =head1 NAME
10 MOBY::Client::CrossReference - a small object describing a MOBY Simple input/output article
12 =head1 SYNOPSIS
14 =head1 DESCRIPTION
16 This holds all of the relevant information for a MOBY cross reference
17 of either the Xref type, or the Object type. Object cross-references
18 have only namespace and id attributes, while Xref cross-references
19 have namespace, id, authURI, serviceName, xref_type, and evidence_code
20 attributes. To determine which type of cross-reference you have
21 in-hand, call the "type" method.
23 =head1 AUTHORS
25 Mark Wilkinson (markw at illuminae dot com)
27 =head1 METHODS
29 =head2 new
31 Usage : my $XR = MOBY::Client::CrossReference->new(%args)
32 Function : create SimpleArticle object
33 Returns : MOBY::Client::CrossReference object
34 Args : type => object || xref (required)
35 namespace => $ns (required)
36 id => $id (required)
37 authURI => $authURI
38 serviceName => $serviceName
39 evidence_code => $evidence_code
40 xref_type=> $xref_ontology_term
41 Object => The XML of a base MOBY Object in this ns/id
44 =head2 type
46 Usage : $type = $XR->type($name)
47 Function : get/set type attribute
48 Returns : string; returns last value if new value set
49 Arguments : (required)one of "xref" or "object", depending on the
50 type of cross-ref you are making (new, or v0.5 API)
52 =head2 namespace
54 Usage : $ns = $XR->namespace($ns)
55 Function : get/set namespace
56 Returns : string; returns last value if new value set
57 Arguments : (optional) string representing namespace to set
59 =head2 id
61 Usage : $id = $XR->id($id)
62 Function : get/set id for the cross-reference
63 Returns : string; returns last value if new value set
64 Arguments : (optional) the id of the cross-reference
66 =head2 authURI
68 Usage : $auth = $XR->authURI($auth)
69 Function : get/set id for the authority for the xref
70 Returns : string; returns last value if new value set
71 Arguments : (optional) the new authority of the xref type reference
73 =head2 serviceName
75 Usage : $name = $XR->serviceName($name)
76 Function : get/set serviceName for the cross-reference
77 Returns : string; returns last value if new value set
78 Arguments : (optional) the new serviceName of the cross-reference
80 =head2 evidence_code
82 Usage : $code = $XR->evidence_code($code)
83 Function : get/set evidence_code for the cross-reference
84 Returns : string; returns last value if new value set
85 Arguments : (optional) the evidence_code of the cross-reference
87 =head2 xref_type
89 Usage : $xreftype = $XR->xref_type($xreftype)
90 Function : get/set xref_type for the cross-reference
91 Returns : string; returns last value if new value set
92 Arguments : (optional) the xref_type of the cross-reference
94 =head2 Object
96 Usage : $XML = $XR->Object()
97 Function : retrieve a base MOBY Object XML (e.g. to send to a service)
98 Returns : XML or empty string if there is no namespace or id value
100 =cut
104 # Why do these methods return the PREVIOUS value of their respective variables?
105 # How would that be useful?
106 # Seems more intuitive to return new value, or perhaps even the object itself.
107 sub type {
108 # only two types are permitted.
109 my ( $self, $type ) = @_;
110 if ($type && ($type =~ /^(xref|object)$/)) {
111 my $old = $self->{_type};
112 $self->{_type} = $type;
113 return $old;
115 return $self->{_type};
118 sub namespace {
119 my ( $self, $type ) = @_;
120 if ($type) {
121 my $old = $self->{_namespace};
122 $self->{_namespace} = $type;
123 return $old;
125 return $self->{_namespace};
128 sub id {
129 my ( $self, $type ) = @_;
130 if ($type) {
131 my $old = $self->{_id};
132 $self->{_id} = $type;
133 return $old;
135 return $self->{_id};
138 sub authURI {
139 my ( $self, $type ) = @_;
140 if ($type) {
141 my $old = $self->{_authURI};
142 $self->{_authURI} = $type;
143 return $old;
145 return $self->{_authURI};
148 sub serviceName {
149 my ( $self, $type ) = @_;
150 if ($type) {
151 my $old = $self->{_serviceName};
152 $self->{_serviceName} = $type;
153 return $old;
155 return $self->{_serviceName};
158 sub evidence_code {
159 my ( $self, $type ) = @_;
160 if ($type) {
161 my $old = $self->{_evidenceCode};
162 $self->{_evidenceCode} = $type;
163 return $old;
165 return $self->{_evidenceCode};
168 sub xref_type {
169 my ( $self, $type ) = @_;
170 if ($type) {
171 my $old = $self->{_xref_type};
172 $self->{_xref_type} = $type;
173 return $old;
175 return $self->{_xref_type};
179 sub new {
180 my ( $caller, %args ) = @_;
181 my $caller_is_obj = ref($caller);
182 return $caller if $caller_is_obj;
183 my $class = $caller_is_obj || $caller;
184 my $proxy;
185 my $self = bless {}, $class;
186 while ( my ( $key, $value ) = each %args ) {
187 $self->$key($value);
189 return undef unless ( $self->type && $self->namespace && $self->id );
190 return $self;
193 sub Object {
194 my ($self) = @_;
195 return "" unless ( $self->namespace && $self->id );
196 return "<moby:Object moby:namespace='"
197 . ( $self->namespace )
198 . "' moby:id='"
199 . ( $self->id ) . "'/>";
201 sub DESTROY { }