00001 =head1 LICENSE 00002 00003 Copyright [2009-2016] EMBL-European Bioinformatics Institute 00004 00005 Licensed under the Apache License, Version 2.0 (the "License"); 00006 you may not use this file except in compliance with the License. 00007 You may obtain a copy of the License at 00008 00009 http://www.apache.org/licenses/LICENSE-2.0 00010 00011 Unless required by applicable law or agreed to in writing, software 00012 distributed under the License is distributed on an "AS IS" BASIS, 00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 See the License for the specific language governing permissions and 00015 limitations under the License. 00016 00017 =head1 CONTACT 00018 00019 Please email comments or questions to the public Ensembl 00020 developers list at <dev@ensembl.org>. 00021 00022 Questions may also be sent to the Ensembl help desk at 00023 <helpdesk@ensembl.org>. 00024 00025 =head1 NAME 00026 00027 Bio::EnsEMBL::MetaData::MetaDataDumper::JsonMetaDataDumper 00028 00029 =head1 SYNOPSIS 00030 00031 =head1 DESCRIPTION 00032 00033 Implementation to dump metadata details to a JSON file. 00034 See Bio::EnsEMBL::MetaData::MetaDataDumper for method details. 00035 00036 =head1 SEE ALSO 00037 Bio::EnsEMBL::MetaData::MetaDataDumper 00038 00039 =head1 AUTHOR 00040 00041 Dan Staines 00042 00043 =cut 00044 00045 package Bio::EnsEMBL::MetaData::MetaDataDumper::JsonMetaDataDumper; 00046 use base qw( Bio::EnsEMBL::MetaData::MetaDataDumper ); 00047 use Carp; 00048 use JSON; 00049 use strict; 00050 use warnings; 00051 use Bio::EnsEMBL::Utils::Argument qw(rearrange); 00052 00053 sub new { 00054 my ($proto, @args) = @_; 00055 my $self = $proto->SUPER::new(@args); 00056 $self->{file} ||= "species_metadata.json"; 00057 return $self; 00058 } 00059 00060 sub start { 00061 my ($self, $divisions, $file, $dump_all) = @_; 00062 $self->SUPER::start($divisions, $file, $dump_all); 00063 for my $fh (values %{$self->{files}}) { 00064 print $fh "[\n"; 00065 } 00066 return; 00067 } 00068 00069 sub _write_metadata_to_file { 00070 my ($self, $md, $fh, $count) = @_; 00071 if($count>0) { 00072 print $fh ",\n"; 00073 } 00074 print $fh to_json($md->to_hash(1), {pretty => 1}); 00075 return; 00076 } 00077 00078 sub end { 00079 my ($self) = @_; 00080 for my $fh (values %{$self->{files}}) { 00081 print $fh "]\n"; 00082 } 00083 $self->SUPER::end(); 00084 return; 00085 } 00086 00087 00088 1; 00089 00090