| 1 | =head1 LICENSE | ||
| 2 | |||
| 3 | See the NOTICE file distributed with this work for additional information | ||
| 4 | regarding copyright ownership. | ||
| 5 | |||
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 7 | you may not use this file except in compliance with the License. | ||
| 8 | You may obtain a copy of the License at | ||
| 9 | |||
| 10 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 11 | |||
| 12 | Unless required by applicable law or agreed to in writing, software | ||
| 13 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 15 | See the License for the specific language governing permissions and | ||
| 16 | limitations under the License. | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | |||
| 21 | =head1 CONTACT | ||
| 22 | |||
| 23 | Please email comments or questions to the public Ensembl | ||
| 24 | developers list at <http://lists.ensembl.org/mailman/listinfo/dev>. | ||
| 25 | |||
| 26 | Questions may also be sent to the Ensembl help desk at | ||
| 27 | <http://www.ensembl.org/Help/Contact>. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | =head1 NAME | ||
| 32 | |||
| 33 | Bio::EnsEMBL::Attribute - A generic Attribute class. | ||
| 34 | |||
| 35 | =head1 SYNOPSIS | ||
| 36 | |||
| 37 | use Bio::EnsEMBL::Attribute; | ||
| 38 | |||
| 39 | my $attribute = Bio::EnsEMBL::Attribute->new | ||
| 40 | (-CODE => 'myCode', | ||
| 41 | -NAME => 'My Attribute', | ||
| 42 | -DESCRIPTION => 'This is my attribute description.', | ||
| 43 | -VALUE => '10023'); | ||
| 44 | |||
| 45 | print $attrib->name(), "\n"; | ||
| 46 | print $attrib->code(), "\n"; | ||
| 47 | print $attrib->description(), "\n"; | ||
| 48 | print $attrib->value(), "\n"; | ||
| 49 | |||
| 50 | =head1 DESCRIPTION | ||
| 51 | |||
| 52 | This is a generic attribute class used to represent attributes | ||
| 53 | associated with seq_regions (and their Slices) and MiscFeatures. | ||
| 54 | |||
| 55 | =head1 SEE ALSO | ||
| 56 | |||
| 57 | Bio::EnsEMBL::Slice | ||
| 58 | Bio::EnsEMBL::MiscFeature | ||
| 59 | Bio::EnsEMBL::DBSQL::AttributeAdaptor | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | package Bio::EnsEMBL::Attribute; | ||
| 64 | $Bio::EnsEMBL::Attribute::VERSION = '114.0.0_50'; # TRIAL | ||
| 65 | $Bio::EnsEMBL::Attribute::VERSION = '114.0.050'; | ||
| 66 | use strict; | ||
| 67 | use warnings; | ||
| 68 | |||
| 69 | use Bio::EnsEMBL::Utils::Argument qw(rearrange); | ||
| 70 | use Scalar::Util qw(weaken isweak); | ||
| 71 | |||
| 72 | =head2 new | ||
| 73 | |||
| 74 | Arg [-CODE] : string - the code for this attribute | ||
| 75 | Arg [-NAME] : string - a human readable name for this attribute | ||
| 76 | Arg [-DESCRIPTION] : string - a description for this attribute | ||
| 77 | Arg [-VALUE] : value - the value of this attribute | ||
| 78 | Example : my $attribute = Bio::EnsEMBL::Attribute->new | ||
| 79 | (-CODE => 'myCode', | ||
| 80 | -NAME => 'My Attribute', | ||
| 81 | -DESCRIPTION => 'This is my attribute description.', | ||
| 82 | -VALUE => '10023'); | ||
| 83 | Description : Constructor. Instantiates a Bio::EnsEMBL::Attribute object. | ||
| 84 | Returntype : Bio::EnsEMBL::Attribute | ||
| 85 | Exceptions : none | ||
| 86 | Caller : general | ||
| 87 | Status : Stable | ||
| 88 | |||
| 89 | =cut | ||
| 90 | |||
| 91 | |||
| 92 | sub new { | ||
| 93 | my $caller = shift; | ||
| 94 | |||
| 95 | # allow to be called as class or object method | ||
| 96 | my $class = ref($caller) || $caller; | ||
| 97 | |||
| 98 | my ($code, $name, $desc, $value) = | ||
| 99 | rearrange([qw(CODE NAME DESCRIPTION VALUE)], @_); | ||
| 100 | |||
| 101 | return bless {'code' => $code, | ||
| 102 | 'name' => $name, | ||
| 103 | 'description' => $desc, | ||
| 104 | 'value' => $value}, $class; | ||
| 105 | } | ||
| 106 | |||
| 107 | =head2 new_fast | ||
| 108 | |||
| 109 | Arg [1] : hashref to be blessed | ||
| 110 | Description: Construct a new Bio::EnsEMBL::Attribute using the hashref. | ||
| 111 | Exceptions : none | ||
| 112 | Returntype : Bio::EnsEMBL::Attribute | ||
| 113 | Caller : general, subclass constructors | ||
| 114 | Status : Stable | ||
| 115 | |||
| 116 | =cut | ||
| 117 | |||
| 118 | |||
| 119 | sub new_fast { | ||
| 120 | my $class = shift; | ||
| 121 | my $hashref = shift; | ||
| 122 | my $self = bless $hashref, $class; | ||
| 123 | weaken($self->{adaptor}) if ( ! isweak($self->{adaptor}) ); | ||
| 124 | return $self; | ||
| 125 | } | ||
| 126 | |||
| 127 | |||
| 128 | =head2 code | ||
| 129 | |||
| 130 | Arg [1] : string $code (optional) | ||
| 131 | Example : $code = $attribute->code(); | ||
| 132 | Description: Getter/Setter for code attribute | ||
| 133 | Returntype : string | ||
| 134 | Exceptions : none | ||
| 135 | Caller : general | ||
| 136 | Status : Stable | ||
| 137 | |||
| 138 | =cut | ||
| 139 | |||
| 140 | sub code { | ||
| 141 | my $self = shift; | ||
| 142 | $self->{'code'} = shift if(@_); | ||
| 143 | return $self->{'code'}; | ||
| 144 | } | ||
| 145 | |||
| 146 | |||
| 147 | =head2 name | ||
| 148 | |||
| 149 | Arg [1] : string $name (optional) | ||
| 150 | Example : $name = $attribute->name(); | ||
| 151 | Description: Getter/Setter for name attribute | ||
| 152 | Returntype : string | ||
| 153 | Exceptions : none | ||
| 154 | Caller : general | ||
| 155 | Status : Stable | ||
| 156 | |||
| 157 | =cut | ||
| 158 | |||
| 159 | sub name { | ||
| 160 | my $self = shift; | ||
| 161 | $self->{'name'} = shift if(@_); | ||
| 162 | return $self->{'name'}; | ||
| 163 | } | ||
| 164 | |||
| 165 | =head2 description | ||
| 166 | |||
| 167 | Arg [1] : string $description (optional) | ||
| 168 | Example : $description = $attribute->description(); | ||
| 169 | Description: Getter/Setter for description attribute | ||
| 170 | Returntype : string | ||
| 171 | Exceptions : none | ||
| 172 | Caller : general | ||
| 173 | Status : Stable | ||
| 174 | |||
| 175 | =cut | ||
| 176 | |||
| 177 | sub description { | ||
| 178 | my $self = shift; | ||
| 179 | $self->{'description'} = shift if(@_); | ||
| 180 | return $self->{'description'}; | ||
| 181 | } | ||
| 182 | |||
| 183 | |||
| 184 | =head2 value | ||
| 185 | |||
| 186 | Arg [1] : string $value (optional) | ||
| 187 | Example : $value = $attribute->value(); | ||
| 188 | Description: Getter/Setter for value attribute | ||
| 189 | Returntype : string | ||
| 190 | Exceptions : none | ||
| 191 | Caller : general | ||
| 192 | Status : Stable | ||
| 193 | |||
| 194 | =cut | ||
| 195 | |||
| 196 | sub value { | ||
| 197 | my $self = shift; | ||
| 198 | $self->{'value'} = shift if(@_); | ||
| 199 | return $self->{'value'}; | ||
| 200 | } | ||
| 201 | |||
| 202 | |||
| 203 | 1; |