Archive Ensembl HomeArchive Ensembl Home
Attribute.pm
Go to the documentation of this file.
00001 =head1 LICENSE
00002 
00003   Copyright (c) 1999-2012 The European Bioinformatics Institute and
00004   Genome Research Limited.  All rights reserved.
00005 
00006   This software is distributed under a modified Apache license.
00007   For license details, please see
00008 
00009     http://www.ensembl.org/info/about/code_licence.html
00010 
00011 =head1 CONTACT
00012 
00013   Please email comments or questions to the public Ensembl
00014   developers list at <dev@ensembl.org>.
00015 
00016   Questions may also be sent to the Ensembl help desk at
00017   <helpdesk@ensembl.org>.
00018 
00019 =cut
00020 
00021 =head1 NAME
00022 
00023 Bio::EnsEMBL::Attribute - A generic Attribute class.
00024 
00025 =head1 SYNOPSIS
00026 
00027   use Bio::EnsEMBL::Attribute;
00028 
00029   my $attribute = Bio::EnsEMBL::Attribute->new
00030        (-CODE => 'myCode',
00031         -NAME => 'My Attribute',
00032         -DESCRIPTION => 'This is my attribute description.',
00033         -VALUE => '10023');
00034 
00035   print $attrib->name(), "\n";
00036   print $attrib->code(), "\n";
00037   print $attrib->description(), "\n";
00038   print $attrib->value(), "\n";
00039 
00040 =head1 DESCRIPTION
00041 
00042 This is a generic attribute class used to represent attributes
00043 associated with seq_regions (and their Slices) and MiscFeatures.
00044 
00045 Also see B<Bio::EnsEMBL::Slice>, B<Bio::EnsEMBL::MiscFeature> and
00046 B<Bio::EnsEMBL::DBSQL::AttributeAdaptor>.
00047 
00048 =head1 METHODS
00049 
00050 =cut
00051 
00052 package Bio::EnsEMBL::Attribute;
00053 
00054 use strict;
00055 use warnings;
00056 
00057 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
00058 use Scalar::Util qw(weaken isweak);
00059 
00060 =head2 new
00061 
00062   Arg [-CODE]   : string - the code for this attribute
00063   Arg [-NAME]   : string - a human readable name for this attribute
00064   Arg [-DESCRIPTION]   : string - a description for this attribute
00065   Arg [-VALUE]  : value  - the value of this attribute
00066   Example    :   my $attribute = Bio::EnsEMBL::Attribute->new
00067                       (-CODE => 'myCode',
00068                        -NAME => 'My Attribute',
00069                        -DESCRIPTION => 'This is my attribute description.',
00070                        -VALUE => '10023');
00071   Description: Constructor.  Instantiates a Bio::EnsEMBL::Attribute object.
00072   Returntype : Bio::EnsEMBL::Attribute
00073   Exceptions : none
00074   Caller     : general
00075   Status     : Stable
00076 
00077 =cut
00078 
00079 
00080 sub new {
00081   my $caller = shift;
00082 
00083   # allow to be called as class or object method
00084   my $class = ref($caller) || $caller;
00085 
00086   my ($code, $name, $desc, $value) =
00087     rearrange([qw(CODE NAME DESCRIPTION VALUE)], @_);
00088 
00089   return bless {'code'    => $code,
00090                 'name'    => $name,
00091                 'description' => $desc,
00092                 'value'   => $value}, $class;
00093 }
00094 
00095 =head2 new_fast
00096 
00097   Arg [1]    : hashref to be blessed
00098   Description: Construct a new Bio::EnsEMBL::Attribute using the hashref.
00099   Exceptions : none
00100   Returntype : Bio::EnsEMBL::Attribute
00101   Caller     : general, subclass constructors
00102   Status     : Stable
00103 
00104 =cut
00105 
00106 
00107 sub new_fast {
00108   my $class = shift;
00109   my $hashref = shift;
00110   my $self = bless $hashref, $class;
00111   weaken($self->{adaptor})  if ( ! isweak($self->{adaptor}) );
00112   return $self;
00113 }
00114 
00115 
00116 =head2 code
00117 
00118   Arg [1]    : string $code (optional)x
00119   Example    : $code = $attribute->code();
00120   Description: Getter/Setter for code attribute
00121   Returntype : string
00122   Exceptions : none
00123   Caller     : general
00124   Status     : Stable
00125 
00126 =cut
00127 
00128 sub code {
00129   my $self = shift;
00130   $self->{'code'} = shift if(@_);
00131   return $self->{'code'};
00132 }
00133 
00134 
00135 =head2 name
00136 
00137   Arg [1]    : string $name (optional)
00138   Example    : $name = $attribute->name();
00139   Description: Getter/Setter for name attribute
00140   Returntype : string
00141   Exceptions : none
00142   Caller     : general
00143   Status     : Stable
00144 
00145 =cut
00146 
00147 sub name {
00148   my $self = shift;
00149   $self->{'name'} = shift if(@_);
00150   return $self->{'name'};
00151 }
00152 
00153 =head2 description
00154 
00155   Arg [1]    : string $description (optional)
00156   Example    : $description = $attribute->description();
00157   Description: Getter/Setter for description attribute
00158   Returntype : string
00159   Exceptions : none
00160   Caller     : general
00161   Status     : Stable
00162 
00163 =cut
00164 
00165 sub description {
00166   my $self = shift;
00167   $self->{'description'} = shift if(@_);
00168   return $self->{'description'};
00169 }
00170 
00171 
00172 =head2 value
00173 
00174   Arg [1]    : string $value (optional)
00175   Example    : $value = $attribute->value();
00176   Description: Getter/Setter for value attribute
00177   Returntype : string
00178   Exceptions : none
00179   Caller     : general
00180   Status     : Stable
00181 
00182 =cut
00183 
00184 sub value {
00185   my $self = shift;
00186   $self->{'value'} = shift if(@_);
00187   return $self->{'value'};
00188 }
00189 
00190 
00191 1;