Archive Ensembl HomeArchive Ensembl Home
MultipleWriter.pm
Go to the documentation of this file.
00001 #
00002 # You may distribute this module under the same terms as perl itself
00003 #
00004 
00005 =pod
00006 
00007 =head1 NAME
00008 
00009 Bio::EnsEMBL::Compara::Production::Projection::Writer::MultipleWriter
00010 
00011 =head1 DESCRIPTION
00012 
00013 A decorator which delegates to the writers given at construction time
00014 and loops through each writer handing off a Projection.
00015 
00016 =head1 AUTHOR
00017 
00018 Andy Yates (ayatesatebiacuk)
00019 
00020 =head1 CONTACT
00021 
00022 This modules is part of the EnsEMBL project (http://www.ensembl.org)
00023 
00024 Questions can be posted to the dev mailing list: dev@ensembl.org
00025 
00026 =cut
00027 
00028 package Bio::EnsEMBL::Compara::Production::Projection::Writer::MultipleWriter;
00029 
00030 use strict;
00031 use warnings;
00032 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
00033 use Bio::EnsEMBL::Utils::Scalar qw(assert_ref);
00034 
00035 use base qw(Bio::EnsEMBL::Compara::Production::Projection::Writer::BaseWriter);
00036 
00037 =head2 new()
00038 
00039   Arg[-writers] : required; ARRAY of the writers to delegate to 1 by 1
00040   Description : New method used for a new instance of the given object. 
00041                 Required fields are indicated accordingly. Fields are specified
00042                 using the Arguments syntax (case insensitive).
00043 
00044 =cut
00045 
00046 sub new {
00047   my ( $class, @args ) = @_;
00048   my $self = $class->SUPER::new(@args);
00049   my ( $writers, ) = rearrange( [qw(writers )], @args );
00050 
00051   assert_ref( $writers, 'ARRAY' );
00052   confess(
00053 'The attribute writers must be specified during construction or provide a builder subroutine'
00054   ) if !defined $writers;
00055   $self->{writers} = $writers if defined $writers;
00056 
00057   return $self;
00058 }
00059 
00060 =head2 writers()
00061 
00062   Description : Getter. 
00063 
00064 =cut
00065 
00066 sub writers {
00067   my ($self) = @_;
00068   return $self->{writers};
00069 }
00070 
00071 =head2 write_projection() 
00072 
00073 Loops through the writers given at construction and will run the 
00074 write_projection() method for each of those.
00075 
00076 =cut
00077 
00078 sub write_projection {
00079   my ($self, $p) = @_;
00080   foreach my $w (@{$self->writers()}) {
00081     $w->write_projection($p);
00082   }
00083   return;
00084 }
00085 
00086 1;