Attribute.pm 4.64 KB
Newer Older
1
=head1 LICENSE
2

3
Copyright [1999-2013] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
4

5 6 7 8 9 10 11 12 13 14 15 16 17
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut
18 19 20 21 22


=head1 CONTACT

  Please email comments or questions to the public Ensembl
Magali Ruffier's avatar
Magali Ruffier committed
23
  developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
24 25

  Questions may also be sent to the Ensembl help desk at
Magali Ruffier's avatar
Magali Ruffier committed
26
  <http://www.ensembl.org/Help/Contact>.
27 28

=cut
29 30 31 32 33 34 35 36 37

=head1 NAME

Bio::EnsEMBL::Attribute - A generic Attribute class.

=head1 SYNOPSIS

  use Bio::EnsEMBL::Attribute;

38 39 40 41 42
  my $attribute = Bio::EnsEMBL::Attribute->new
       (-CODE => 'myCode',
        -NAME => 'My Attribute',
        -DESCRIPTION => 'This is my attribute description.',
        -VALUE => '10023');
43

44 45
  print $attrib->name(), "\n";
  print $attrib->code(), "\n";
46
  print $attrib->description(), "\n";
47
  print $attrib->value(), "\n";
48 49 50 51 52 53

=head1 DESCRIPTION

This is a generic attribute class used to represent attributes
associated with seq_regions (and their Slices) and MiscFeatures.

Kieron Taylor's avatar
Kieron Taylor committed
54
=head1 SEE ALSO
55

Kieron Taylor's avatar
Kieron Taylor committed
56 57 58
Bio::EnsEMBL::Slice
Bio::EnsEMBL::MiscFeature
Bio::EnsEMBL::DBSQL::AttributeAdaptor
59 60 61

=cut

62 63
package Bio::EnsEMBL::Attribute;

64 65 66 67
use strict;
use warnings;

use Bio::EnsEMBL::Utils::Argument qw(rearrange);
Monika Komorowska's avatar
Monika Komorowska committed
68
use Scalar::Util qw(weaken isweak);
69 70 71

=head2 new

Kieron Taylor's avatar
Kieron Taylor committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85
  Arg [-CODE]        : string - the code for this attribute
  Arg [-NAME]        : string - a human readable name for this attribute
  Arg [-DESCRIPTION] : string - a description for this attribute
  Arg [-VALUE]       : value  - the value of this attribute
  Example            :   my $attribute = Bio::EnsEMBL::Attribute->new
                         (-CODE => 'myCode',
                          -NAME => 'My Attribute',
                          -DESCRIPTION => 'This is my attribute description.',
                          -VALUE => '10023');
  Description        : Constructor.  Instantiates a Bio::EnsEMBL::Attribute object.
  Returntype         : Bio::EnsEMBL::Attribute
  Exceptions         : none
  Caller             : general
  Status             : Stable
86 87 88 89 90 91 92 93 94 95 96

=cut


sub new {
  my $caller = shift;

  # allow to be called as class or object method
  my $class = ref($caller) || $caller;

  my ($code, $name, $desc, $value) =
97
    rearrange([qw(CODE NAME DESCRIPTION VALUE)], @_);
98 99 100

  return bless {'code'    => $code,
                'name'    => $name,
101
                'description' => $desc,
102 103 104
                'value'   => $value}, $class;
}

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
=head2 new_fast

  Arg [1]    : hashref to be blessed
  Description: Construct a new Bio::EnsEMBL::Attribute using the hashref.
  Exceptions : none
  Returntype : Bio::EnsEMBL::Attribute
  Caller     : general, subclass constructors
  Status     : Stable

=cut


sub new_fast {
  my $class = shift;
  my $hashref = shift;
Monika Komorowska's avatar
Monika Komorowska committed
120 121 122
  my $self = bless $hashref, $class;
  weaken($self->{adaptor})  if ( ! isweak($self->{adaptor}) );
  return $self;
123 124
}

125 126 127

=head2 code

Kieron Taylor's avatar
Kieron Taylor committed
128
  Arg [1]    : string $code (optional)
129 130 131 132 133
  Example    : $code = $attribute->code();
  Description: Getter/Setter for code attribute
  Returntype : string
  Exceptions : none
  Caller     : general
134
  Status     : Stable
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152

=cut

sub code {
  my $self = shift;
  $self->{'code'} = shift if(@_);
  return $self->{'code'};
}


=head2 name

  Arg [1]    : string $name (optional)
  Example    : $name = $attribute->name();
  Description: Getter/Setter for name attribute
  Returntype : string
  Exceptions : none
  Caller     : general
153
  Status     : Stable
154 155 156 157 158 159 160 161 162

=cut

sub name {
  my $self = shift;
  $self->{'name'} = shift if(@_);
  return $self->{'name'};
}

163
=head2 description
164

165 166
  Arg [1]    : string $description (optional)
  Example    : $description = $attribute->description();
167 168 169 170
  Description: Getter/Setter for description attribute
  Returntype : string
  Exceptions : none
  Caller     : general
171
  Status     : Stable
172 173 174

=cut

175
sub description {
176
  my $self = shift;
177 178
  $self->{'description'} = shift if(@_);
  return $self->{'description'};
179 180 181 182 183 184 185 186 187 188 189
}


=head2 value

  Arg [1]    : string $value (optional)
  Example    : $value = $attribute->value();
  Description: Getter/Setter for value attribute
  Returntype : string
  Exceptions : none
  Caller     : general
190
  Status     : Stable
191 192 193 194 195 196 197 198 199 200 201

=cut

sub value {
  my $self = shift;
  $self->{'value'} = shift if(@_);
  return $self->{'value'};
}


1;