Bio-Phylo
view release on metacpan or search on metacpan
lib/Bio/Phylo/NeXML/Writable.pm view on Meta::CPAN
Serializes object to JSON string
Type : Serializer
Title : to_json()
Usage : print $obj->to_json();
Function: Serializes object to JSON string
Returns : String
Args : None
Comments:
=cut
sub to_json {
looks_like_class('Bio::Phylo::NeXML::XML2JSON')->new->convert( shift->to_xml );
}
sub _json_data {
my $self = shift;
my %meta = map { $_->get_predicate => $_->get_object } @{ $self->get_meta };
my %result = %{ $self->SUPER::_json_data };
$result{$_} = $meta{$_} for keys %meta;
$result{'name'} = $self->get_name if $self->get_name;
$result{'link'} = $self->get_link if $self->get_link;
return \%result;
}
=item to_cdao()
Serializes object to CDAO RDF/XML string
Type : Serializer
Title : to_cdao()
Usage : print $obj->to_cdao();
Function: Serializes object to CDAO RDF/XML string
Returns : String
Args : None
Comments:
=cut
sub to_cdao {
return unparse(
'-phylo' => shift,
'-format' => 'cdao',
);
}
sub _cleanup : Destructor {
my $self = shift;
# this deserves an explanation. the issue is as follows: for the package
# bio-phylo-megatree we have node objects that are persisted in a database
# and accessed through an object-relational mapping provided by DBIx::Class.
# these node objects are created and destroyed on the fly as a set of node
# records (i.e. a tree) is traversed. this is the whole point of the package,
# because it means large trees don't ever have to be kept in memory. however,
# as a consequence, every time one of those ORM-backed nodes goes out of scope,
# this destructor is called and all the @fields are cleaned up again. this
# precludes computation and caching of node coordinates (or any other semantic
# annotation) on such ORM-backed objects. the terrible, terrible fix for now is
# to just assume that i) these annotations need to stay alive ii) we're not going
# to have ID clashes (!!!!!), so iii) we just don't clean up after ourselves.
# as a note to my future self: it would be a good idea to have a triple store-like
# table to store the annotations, so they are persisted in the same way as the
# node objects, bypassing this malarkey.
if ( not $self->isa('DBIx::Class::Core') ) {
my $id = $self->get_id;
for my $field (@fields) {
delete $field->{$id};
}
}
}
=back
=cut
# podinherit_insert_token
=head1 SEE ALSO
There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
for any user or developer questions and discussions.
Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>.
=head1 CITATION
If you use Bio::Phylo in published research, please cite it:
B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
I<BMC Bioinformatics> B<12>:63.
L<http://dx.doi.org/10.1186/1471-2105-12-63>
=cut
}
1;
( run in 2.123 seconds using v1.01-cache-2.11-cpan-14f38c9f855 )