| 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'; | ||
| 65 | use strict; | ||
| 66 | use warnings; | ||
| 67 | |||
| 68 | use Bio::EnsEMBL::Utils::Argument qw(rearrange); | ||
| 69 | use Scalar::Util qw(weaken isweak); | ||
| 70 | |||
| 71 | =head2 new | ||
| 72 | |||
| 73 | Arg [-CODE] : string - the code for this attribute | ||
| 74 | Arg [-NAME] : string - a human readable name for this attribute | ||
| 75 | Arg [-DESCRIPTION] : string - a description for this attribute | ||
| 76 | Arg [-VALUE] : value - the value of this attribute | ||
| 77 | Example : my $attribute = Bio::EnsEMBL::Attribute->new | ||
| 78 | (-CODE => 'myCode', | ||
| 79 | -NAME => 'My Attribute', | ||
| 80 | -DESCRIPTION => 'This is my attribute description.', | ||
| 81 | -VALUE => '10023'); | ||
| 82 | Description : Constructor. Instantiates a Bio::EnsEMBL::Attribute object. | ||
| 83 | Returntype : Bio::EnsEMBL::Attribute | ||
| 84 | Exceptions : none | ||
| 85 | Caller : general | ||
| 86 | Status : Stable | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | |||
| 91 | sub new { | ||
| 92 | my $caller = shift; | ||
| 93 | |||
| 94 | # allow to be called as class or object method | ||
| 95 | my $class = ref($caller) || $caller; | ||
| 96 | |||
| 97 | my ($code, $name, $desc, $value) = | ||
| 98 | rearrange([qw(CODE NAME DESCRIPTION VALUE)], @_); | ||
| 99 | |||
| 100 | return bless {'code' => $code, | ||
| 101 | 'name' => $name, | ||
| 102 | 'description' => $desc, | ||
| 103 | 'value' => $value}, $class; | ||
| 104 | } | ||
| 105 | |||
| 106 | =head2 new_fast | ||
| 107 | |||
| 108 | Arg [1] : hashref to be blessed | ||
| 109 | Description: Construct a new Bio::EnsEMBL::Attribute using the hashref. | ||
| 110 | Exceptions : none | ||
| 111 | Returntype : Bio::EnsEMBL::Attribute | ||
| 112 | Caller : general, subclass constructors | ||
| 113 | Status : Stable | ||
| 114 | |||
| 115 | =cut | ||
| 116 | |||
| 117 | |||
| 118 | sub new_fast { | ||
| 119 | my $class = shift; | ||
| 120 | my $hashref = shift; | ||
| 121 | my $self = bless $hashref, $class; | ||
| 122 | weaken($self->{adaptor}) if ( ! isweak($self->{adaptor}) ); | ||
| 123 | return $self; | ||
| 124 | } | ||
| 125 | |||
| 126 | |||
| 127 | =head2 code | ||
| 128 | |||
| 129 | Arg [1] : string $code (optional) | ||
| 130 | Example : $code = $attribute->code(); | ||
| 131 | Description: Getter/Setter for code attribute | ||
| 132 | Returntype : string | ||
| 133 | Exceptions : none | ||
| 134 | Caller : general | ||
| 135 | Status : Stable | ||
| 136 | |||
| 137 | =cut | ||
| 138 | |||
| 139 | sub code { | ||
| 140 | my $self = shift; | ||
| 141 | $self->{'code'} = shift if(@_); | ||
| 142 | return $self->{'code'}; | ||
| 143 | } | ||
| 144 | |||
| 145 | |||
| 146 | =head2 name | ||
| 147 | |||
| 148 | Arg [1] : string $name (optional) | ||
| 149 | Example : $name = $attribute->name(); | ||
| 150 | Description: Getter/Setter for name attribute | ||
| 151 | Returntype : string | ||
| 152 | Exceptions : none | ||
| 153 | Caller : general | ||
| 154 | Status : Stable | ||
| 155 | |||
| 156 | =cut | ||
| 157 | |||
| 158 | sub name { | ||
| 159 | my $self = shift; | ||
| 160 | $self->{'name'} = shift if(@_); | ||
| 161 | return $self->{'name'}; | ||
| 162 | } | ||
| 163 | |||
| 164 | =head2 description | ||
| 165 | |||
| 166 | Arg [1] : string $description (optional) | ||
| 167 | Example : $description = $attribute->description(); | ||
| 168 | Description: Getter/Setter for description attribute | ||
| 169 | Returntype : string | ||
| 170 | Exceptions : none | ||
| 171 | Caller : general | ||
| 172 | Status : Stable | ||
| 173 | |||
| 174 | =cut | ||
| 175 | |||
| 176 | sub description { | ||
| 177 | my $self = shift; | ||
| 178 | $self->{'description'} = shift if(@_); | ||
| 179 | return $self->{'description'}; | ||
| 180 | } | ||
| 181 | |||
| 182 | |||
| 183 | =head2 value | ||
| 184 | |||
| 185 | Arg [1] : string $value (optional) | ||
| 186 | Example : $value = $attribute->value(); | ||
| 187 | Description: Getter/Setter for value attribute | ||
| 188 | Returntype : string | ||
| 189 | Exceptions : none | ||
| 190 | Caller : general | ||
| 191 | Status : Stable | ||
| 192 | |||
| 193 | =cut | ||
| 194 | |||
| 195 | sub value { | ||
| 196 | my $self = shift; | ||
| 197 | $self->{'value'} = shift if(@_); | ||
| 198 | return $self->{'value'}; | ||
| 199 | } | ||
| 200 | |||
| 201 | |||
| 202 | 1; |