00001 00002 =head1 LICENSE 00003 00004 Copyright [1999-2014] EMBL-European Bioinformatics Institute 00005 00006 Licensed under the Apache License, Version 2.0 (the "License"); 00007 you may not use this file except in compliance with the License. 00008 You may obtain a copy of the License at 00009 00010 http://www.apache.org/licenses/LICENSE-2.0 00011 00012 Unless required by applicable law or agreed to in writing, software 00013 distributed under the License is distributed on an "AS IS" BASIS, 00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 See the License for the specific language governing permissions and 00016 limitations under the License. 00017 00018 =head1 CONTACT 00019 00020 Please email comments or questions to the public Ensembl 00021 developers list at <dev@ensembl.org>. 00022 00023 Questions may also be sent to the Ensembl help desk at 00024 <helpdesk@ensembl.org>. 00025 =head1 NAME 00026 00027 Bio::EnsEMBL::MetaData::EventInfo 00028 00029 =head1 SYNOPSIS 00030 00031 my $event_info = 00032 Bio::EnsEMBL::MetaData::EventInfo->new( 00033 -ENSEMBL_VERSION=>83, 00034 -EG_VERSION=>30, 00035 -DATE=>'2015-12-07'); 00036 00037 =head1 DESCRIPTION 00038 00039 Object encapsulating information about an event that concerns a metadata object 00040 00041 =head1 SEE ALSO 00042 00043 Bio::EnsEMBL::MetaData::BaseInfo 00044 Bio::EnsEMBL::MetaData::DBSQL::EventInfoAdaptor 00045 00046 =head1 Author 00047 00048 Dan Staines 00049 00050 =cut 00051 00052 package Bio::EnsEMBL::MetaData::EventInfo; 00053 use base qw/Bio::EnsEMBL::MetaData::BaseInfo/; 00054 use strict; 00055 use warnings; 00056 00057 use Bio::EnsEMBL::Utils::Argument qw(rearrange); 00058 use Bio::EnsEMBL::Utils::Exception qw(throw); 00059 00060 =head1 CONSTRUCTOR 00061 =head2 new 00062 Arg [-SUBJECT] : 00063 object : subject of the event (GenomeInfo, DatabaseInfo, GenomeComparaInfo) 00064 Arg [-TYPE] : 00065 string - type of event 00066 Arg [-SOURCE] : 00067 string - ID of the source of the event 00068 00069 Example : $info = Bio::EnsEMBL::MetaData::DataReleaseInfo->new(...); 00070 Description: Creates a new release info object 00071 Returntype : Bio::EnsEMBL::MetaData::DataReleaseInfo 00072 Exceptions : none 00073 Caller : general 00074 Status : Stable 00075 00076 =cut 00077 00078 sub new { 00079 my ( $class, @args ) = @_; 00080 my $self = $class->SUPER::new(@args); 00081 my $subject; 00082 ( $subject, $self->{type}, $self->{source}, $self->{details}, 00083 $self->{timestamp} ) 00084 = rearrange( [ 'SUBJECT', 'TYPE', 'SOURCE', 'DETAILS', 'TIMESTAMP' ], 00085 @args ); 00086 $self->subject($subject); 00087 return $self; 00088 } 00089 00090 =head1 ATTRIBUTE METHODS 00091 =head2 subject 00092 Description: Get/set subject of event 00093 Arg : (optional) Subject to set (must be GenomeInfo, DatabaseInfo or GenomeComparaInfo) 00094 Returntype : Bio::EnsEMBL::MetaData::BaseInfo 00095 Exceptions : none 00096 Caller : general 00097 Status : Stable 00098 =cut 00099 00100 sub subject { 00101 my ( $self, $subject ) = @_; 00102 if ( defined $subject ) { 00103 if ( !$subject->isa("Bio::EnsEMBL::MetaData::GenomeInfo") && 00104 !$subject->isa("Bio::EnsEMBL::MetaData::DatabaseInfo") && 00105 !$subject->isa("Bio::EnsEMBL::MetaData::GenomeComparaInfo") ) 00106 { 00107 throw "Subject must be GenomeInfo, DatabaseInfo or GenomeComparaInfo"; 00108 } 00109 $self->{subject} = $subject; 00110 } 00111 return $self->{subject}; 00112 } 00113 00114 =head2 type 00115 Description: Get/set subject of event 00116 Arg : (optional) String 00117 Returntype : String 00118 Exceptions : none 00119 Caller : general 00120 Status : Stable 00121 =cut 00122 00123 sub type { 00124 my ( $self, $type ) = @_; 00125 $self->{type} = $type if ( defined $type ); 00126 return $self->{type}; 00127 } 00128 00129 =head2 subject 00130 Description: Get/set source of event 00131 Arg : (optional) String 00132 Returntype : String 00133 Exceptions : none 00134 Caller : general 00135 Status : Stable 00136 =cut 00137 00138 sub source { 00139 my ( $self, $source ) = @_; 00140 $self->{source} = $source if ( defined $source ); 00141 return $self->{source}; 00142 } 00143 00144 =head2 details 00145 Description: Get/set details of event 00146 Arg : (optional) String 00147 Returntype : String 00148 Exceptions : none 00149 Caller : general 00150 Status : Stable 00151 =cut 00152 00153 sub details { 00154 my ( $self, $details ) = @_; 00155 $self->{details} = $details if ( defined $details ); 00156 return $self->{details}; 00157 00158 } 00159 00160 =head2 subject 00161 Description: Get timestamp of event 00162 Returntype : String (YYYY-MM-DD HH:MM::SS) 00163 Exceptions : none 00164 Caller : general 00165 Status : Stable 00166 =cut 00167 00168 sub timestamp { 00169 my ( $self, $timestamp ) = @_; 00170 return $self->{timestamp}; 00171 } 00172 00173 =head2 to_hash 00174 Description: Render as plain hash suitable for export as JSON/XML 00175 Returntype : Hashref 00176 Exceptions : none 00177 Caller : general 00178 Status : Stable 00179 =cut 00180 00181 sub to_hash { 00182 my ($in) = @_; 00183 return { subject => $in->subject()->to_hash(), 00184 type => $in->type(), 00185 source => $in->source(), 00186 details => $in->details(), 00187 timestamp => $in->timestamp() }; 00188 } 00189 =head2 to_string 00190 Description: Render as string suitable for display 00191 Returntype : String 00192 Exceptions : none 00193 Caller : general 00194 Status : Stable 00195 =cut 00196 sub to_string { 00197 my ($self) = @_; 00198 return 00199 join( ":", 00200 $self->subject()->to_string(), $self->type(), 00201 $self->source(), $self->details(), 00202 ( $self->timestamp() || '-' ) ); 00203 } 00204 00205 1;