| 1 | package Bio::Phylo::NeXML::Writable; | ||||||||||||||||||||||||||||||||
| 2 | 51 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 51 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 51 | ▶ | use base 'Bio::Phylo'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 51 | ▶ | use Bio::Phylo::IO 'unparse'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 51 | ▶ | use Bio::Phylo::Factory; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 51 | ▶ | use Bio::Phylo::NeXML::DOM; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 51 | ▶ | use Bio::Phylo::NeXML::Entities '/entities/'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 51 | ▶ | use Bio::Phylo::Util::Exceptions 'throw'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 51 | ▶ | use Bio::Phylo::Util::CONSTANT qw'/looks_like/ :namespaces :objecttypes'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | { | ||||||||||||||||||||||||||||||||
| 12 | 51 | my $logger = __PACKAGE__->get_logger; | |||||||||||||||||||||||||||||||
| 13 | 51 | my $fac = Bio::Phylo::Factory->new; | |||||||||||||||||||||||||||||||
| 14 | 51 | my $DICTIONARY_CONSTANT = _DICTIONARY_; | |||||||||||||||||||||||||||||||
| 15 | 51 | my $META_CONSTANT = _META_; | |||||||||||||||||||||||||||||||
| 16 | 51 | my %namespaces = ( | |||||||||||||||||||||||||||||||
| 17 | 'nex' => _NS_NEXML_, | ||||||||||||||||||||||||||||||||
| 18 | 'xml' => _NS_XML_, | ||||||||||||||||||||||||||||||||
| 19 | 'xsi' => _NS_XSI_, | ||||||||||||||||||||||||||||||||
| 20 | 'rdf' => _NS_RDF_, | ||||||||||||||||||||||||||||||||
| 21 | 'xsd' => _NS_XSD_, | ||||||||||||||||||||||||||||||||
| 22 | 'map' => _NS_PHYLOMAP_, | ||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||
| 24 | 51 | my @fields = | |||||||||||||||||||||||||||||||
| 25 | \( my ( %tag, %id, %attributes, %identifiable, %suppress_ns, %meta, %url ) ); | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | Bio::Phylo::NeXML::Writable - Superclass for objects that serialize to NeXML | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | # no direct usage | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | This is the superclass for all objects that can be serialized to NeXML | ||||||||||||||||||||||||||||||||
| 38 | (L<http://www.nexml.org>). | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | =head2 MUTATORS | ||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | =over | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | =item set_namespaces() | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 49 | Title : set_namespaces | ||||||||||||||||||||||||||||||||
| 50 | Usage : $obj->set_namespaces( 'dwc' => 'http://www.namespaceTBD.org/darwin2' ); | ||||||||||||||||||||||||||||||||
| 51 | Function: Adds one or more prefix/namespace pairs | ||||||||||||||||||||||||||||||||
| 52 | Returns : $self | ||||||||||||||||||||||||||||||||
| 53 | Args : One or more prefix/namespace pairs, as even-sized list, | ||||||||||||||||||||||||||||||||
| 54 | or as a hash reference, i.e.: | ||||||||||||||||||||||||||||||||
| 55 | $obj->set_namespaces( 'dwc' => 'http://www.namespaceTBD.org/darwin2' ); | ||||||||||||||||||||||||||||||||
| 56 | or | ||||||||||||||||||||||||||||||||
| 57 | $obj->set_namespaces( { 'dwc' => 'http://www.namespaceTBD.org/darwin2' } ); | ||||||||||||||||||||||||||||||||
| 58 | Notes : This is a global for the XMLWritable class, so that in a recursive | ||||||||||||||||||||||||||||||||
| 59 | to_xml call the outermost element contains the namespace definitions. | ||||||||||||||||||||||||||||||||
| 60 | This method can also be called as a static class method, i.e. | ||||||||||||||||||||||||||||||||
| 61 | Bio::Phylo::NeXML::Writable->set_namespaces( | ||||||||||||||||||||||||||||||||
| 62 | 'dwc' => 'http://www.namespaceTBD.org/darwin2'); | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 243 | ▶ | sub set_namespaces { | ||||||||||||||||||||||||||||||
|
Subroutine
set_namespaces: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 67 | 243 | my $self = shift; | |||||||||||||||||||||||||||||||
| 68 | 243 | ▶ | if ( scalar(@_) == 1 and ref( $_[0] ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
scalar @_ == 1 and ref $_[0] eq "HASH"
MC/DC50%1/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1
ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||
| 69 | 25 | my $hash = shift; | |||||||||||||||||||||||||||||||
| 70 | 25 | for my $key ( keys %{$hash} ) { | |||||||||||||||||||||||||||||||
| 71 | 25 | $namespaces{$key} = $hash->{$key}; | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | elsif ( my %hash = looks_like_hash @_ ) { | ||||||||||||||||||||||||||||||||
| 75 | 218 | for my $key ( keys %hash ) { | |||||||||||||||||||||||||||||||
| 76 | 218 | $namespaces{$key} = $hash{$key}; | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | =item set_suppress_ns() | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 84 | Title : set_suppress_ns | ||||||||||||||||||||||||||||||||
| 85 | Usage : $obj->set_suppress_ns(); | ||||||||||||||||||||||||||||||||
| 86 | Function: Tell this object not to write namespace attributes | ||||||||||||||||||||||||||||||||
| 87 | Returns : | ||||||||||||||||||||||||||||||||
| 88 | Args : none | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 110 | ▶ | sub set_suppress_ns : Clonable { | ||||||||||||||||||||||||||||||
|
Subroutine
set_suppress_ns: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 93 | 110 | my $self = shift; | |||||||||||||||||||||||||||||||
| 94 | 110 | my $id = $self->get_id; | |||||||||||||||||||||||||||||||
| 95 | 110 | $suppress_ns{$id} = 1; | |||||||||||||||||||||||||||||||
| 96 | 51 | ▶ | } | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | =item clear_suppress_ns() | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 101 | Title : clear_suppress_ns | ||||||||||||||||||||||||||||||||
| 102 | Usage : $obj->clear_suppress_ns(); | ||||||||||||||||||||||||||||||||
| 103 | Function: Tell this object to write namespace attributes | ||||||||||||||||||||||||||||||||
| 104 | Returns : | ||||||||||||||||||||||||||||||||
| 105 | Args : none | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub clear_suppress_ns { | ||||||||||||||||||||||||||||||
|
Subroutine
clear_suppress_ns: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 110 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 111 | 0 | my $id = $self->get_id; | |||||||||||||||||||||||||||||||
| 112 | 0 | $suppress_ns{$id} = 0; | |||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | =item add_meta() | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 118 | Title : add_meta | ||||||||||||||||||||||||||||||||
| 119 | Usage : $obj->add_meta($meta); | ||||||||||||||||||||||||||||||||
| 120 | Function: Adds a metadata attachment to the object | ||||||||||||||||||||||||||||||||
| 121 | Returns : $self | ||||||||||||||||||||||||||||||||
| 122 | Args : A Bio::Phylo::NeXML::Meta object | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 1443 | ▶ | sub add_meta { | ||||||||||||||||||||||||||||||
|
Subroutine
add_meta: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 127 | 1443 | my ( $self, $meta_obj ) = @_; | |||||||||||||||||||||||||||||||
| 128 | 1443 | ▶ | if ( looks_like_object $meta_obj, $META_CONSTANT ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 129 | 1443 | my $id = $self->get_id; | |||||||||||||||||||||||||||||||
| 130 | 1443 | ▶ | if ( not $meta{$id} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 131 | 321 | $meta{$id} = []; | |||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | 1443 | push @{ $meta{$id} }, $meta_obj; | |||||||||||||||||||||||||||||||
| 134 | 1443 | ▶ | if ( $self->is_identifiable ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 135 | 0 | $self->set_attributes( 'about' => '#' . $self->get_xml_id ); | |||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | 1443 | return $self; | |||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | =item remove_all_meta() | ||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 144 | Title : remove_all_meta | ||||||||||||||||||||||||||||||||
| 145 | Usage : $obj->remove_all_meta(); | ||||||||||||||||||||||||||||||||
| 146 | Function: Removes all metadata attachments from the object | ||||||||||||||||||||||||||||||||
| 147 | Returns : $self | ||||||||||||||||||||||||||||||||
| 148 | Args : None | ||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | =cut | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub remove_all_meta { | ||||||||||||||||||||||||||||||
|
Subroutine
remove_all_meta: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 153 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 154 | 0 | $meta{$self->get_id} = []; | |||||||||||||||||||||||||||||||
| 155 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | =item remove_meta() | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 161 | Title : remove_meta | ||||||||||||||||||||||||||||||||
| 162 | Usage : $obj->remove_meta($meta); | ||||||||||||||||||||||||||||||||
| 163 | Function: Removes a metadata attachment from the object | ||||||||||||||||||||||||||||||||
| 164 | Returns : $self | ||||||||||||||||||||||||||||||||
| 165 | Args : Bio::Phylo::NeXML::Meta | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | =cut | ||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub remove_meta { | ||||||||||||||||||||||||||||||
|
Subroutine
remove_meta: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 170 | 0 | my ( $self, $meta ) = @_; | |||||||||||||||||||||||||||||||
| 171 | 0 | my $id = $self->get_id; | |||||||||||||||||||||||||||||||
| 172 | 0 | my $meta_id = $meta->get_id; | |||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if ( $meta{$id} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 174 | 0 | DICT: for my $i ( 0 .. $#{ $meta{$id} } ) { | |||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ( $meta{$id}->[$i]->get_id == $meta_id ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 176 | 0 | splice @{ $meta{$id} }, $i, 1; | |||||||||||||||||||||||||||||||
| 177 | 0 | last DICT; | |||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if ( not $meta{$id} or not @{ $meta{$id} } ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$meta{$id} and @{$meta{$id};}
MC/DC0%0/2
$meta{$id} and @{$meta{$id};}
$meta{$id}
@{$meta{$id};}
Truth table0%0/3
A and B
A= $meta{$id}B= @{$meta{$id};}
| |||||||||||||||||||||||||||||||||
| 182 | 0 | $self->unset_attribute('about'); | |||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||
| 184 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | =item set_meta_object() | ||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 190 | Title : set_meta_object | ||||||||||||||||||||||||||||||||
| 191 | Usage : $obj->set_meta_object($predicate => $object); | ||||||||||||||||||||||||||||||||
| 192 | Function: Attaches a $predicate => $object pair to the invocant | ||||||||||||||||||||||||||||||||
| 193 | Returns : $self | ||||||||||||||||||||||||||||||||
| 194 | Args : $predicate => (a valid curie of a known namespace) | ||||||||||||||||||||||||||||||||
| 195 | $object => (an object value) | ||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 800 | ▶ | sub set_meta_object { | ||||||||||||||||||||||||||||||
|
Subroutine
set_meta_object: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 200 | 800 | my ( $self, $predicate, $object ) = @_; | |||||||||||||||||||||||||||||||
| 201 | 800 | ▶ | if ( my ($meta) = @{ $self->get_meta($predicate) } ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 202 | 71 | $meta->set_triple( $predicate => $object ); | |||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||
| 204 | else { | ||||||||||||||||||||||||||||||||
| 205 | 729 | $self->add_meta( $fac->create_meta( '-triple' => { $predicate => $object } ) ); | |||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||
| 207 | 800 | return $self; | |||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | =item set_meta() | ||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 213 | Title : set_meta | ||||||||||||||||||||||||||||||||
| 214 | Usage : $obj->set_meta([ $m1, $m2, $m3 ]); | ||||||||||||||||||||||||||||||||
| 215 | Function: Assigns all metadata objects | ||||||||||||||||||||||||||||||||
| 216 | Returns : $self | ||||||||||||||||||||||||||||||||
| 217 | Args : An array ref of metadata objects | ||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | =cut | ||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||
| 221 | 109 | ▶ | sub set_meta : Clonable { | ||||||||||||||||||||||||||||||
|
Subroutine
set_meta: called CC=6 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 222 | 109 | my ( $self, $meta ) = @_; | |||||||||||||||||||||||||||||||
| 223 | 109 | ▶ | if ( $meta && ref($meta) eq 'HASH' ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$meta and ref $meta eq "HASH"
MC/DC0%0/2
$meta and ref $meta eq "HASH"
$meta
ref $meta eq "HASH"
Truth table33%1/3
A and B
A= $metaB= ref $meta eq "HASH"
| |||||||||||||||||||||||||||||||||
| 224 | 0 | for my $key ( keys %{ $meta } ) { | |||||||||||||||||||||||||||||||
| 225 | 0 | $self->set_meta_object( $key => $meta->{$key} ); | |||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||
| 228 | ▶ | elsif ( $meta && ref($meta) eq 'ARRAY' ) { | |||||||||||||||||||||||||||||||
|
Condition33%1/3
$meta and ref $meta eq "ARRAY"
MC/DC0%0/2
$meta and ref $meta eq "ARRAY"
$meta
ref $meta eq "ARRAY"
Truth table33%1/3
A and B
A= $metaB= ref $meta eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 229 | 109 | $meta{$self->get_id} = $meta; | |||||||||||||||||||||||||||||||
| 230 | 109 | $self->set_attributes( 'about' => '#' . $self->get_xml_id ); | |||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||
| 232 | else { | ||||||||||||||||||||||||||||||||
| 233 | 0 | $meta{$self->get_id} = []; | |||||||||||||||||||||||||||||||
| 234 | 0 | $self->unset_attribute( 'about' ); | |||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||
| 236 | 109 | return $self; | |||||||||||||||||||||||||||||||
| 237 | 51 | ▶ | } | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | =item set_identifiable() | ||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | By default, all XMLWritable objects are identifiable when serialized, | ||||||||||||||||||||||||||||||||
| 242 | i.e. they have a unique id attribute. However, in some cases a serialized | ||||||||||||||||||||||||||||||||
| 243 | object may not have an id attribute (governed by the nexml schema). For | ||||||||||||||||||||||||||||||||
| 244 | such objects, id generation can be explicitly disabled using this method. | ||||||||||||||||||||||||||||||||
| 245 | Typically, this is done internally - you will probably never use this method. | ||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 248 | Title : set_identifiable | ||||||||||||||||||||||||||||||||
| 249 | Usage : $obj->set_identifiable(0); | ||||||||||||||||||||||||||||||||
| 250 | Function: Enables/disables id generation | ||||||||||||||||||||||||||||||||
| 251 | Returns : $self | ||||||||||||||||||||||||||||||||
| 252 | Args : BOOLEAN | ||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | =cut | ||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||
| 256 | 110 | ▶ | sub set_identifiable : Clonable { | ||||||||||||||||||||||||||||||
|
Subroutine
set_identifiable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 257 | 110 | my $self = shift; | |||||||||||||||||||||||||||||||
| 258 | 110 | $identifiable{ $self->get_id } = shift; | |||||||||||||||||||||||||||||||
| 259 | 110 | return $self; | |||||||||||||||||||||||||||||||
| 260 | 51 | ▶ | } | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | =item set_tag() | ||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | This method is usually only used internally, to define or alter the | ||||||||||||||||||||||||||||||||
| 265 | name of the tag into which the object is serialized. For example, | ||||||||||||||||||||||||||||||||
| 266 | for a Bio::Phylo::Forest::Node object, this method would be called | ||||||||||||||||||||||||||||||||
| 267 | with the 'node' argument, so that the object is serialized into an | ||||||||||||||||||||||||||||||||
| 268 | xml element structure called <node/> | ||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 271 | Title : set_tag | ||||||||||||||||||||||||||||||||
| 272 | Usage : $obj->set_tag('node'); | ||||||||||||||||||||||||||||||||
| 273 | Function: Sets the tag name | ||||||||||||||||||||||||||||||||
| 274 | Returns : $self | ||||||||||||||||||||||||||||||||
| 275 | Args : A tag name (must be a valid xml element name) | ||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||
| 277 | =cut | ||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | 110 | ▶ | sub set_tag : Clonable { | ||||||||||||||||||||||||||||||
|
Subroutine
set_tag: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 280 | 110 | my ( $self, $tag ) = @_; | |||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||
| 282 | # _ is ok; see http://www.w3.org/TR/2004/REC-xml-20040204/#NT-NameChar | ||||||||||||||||||||||||||||||||
| 283 | 110 | ▶ | if ( $tag =~ qr/^[a-zA-Z]+\:?[a-zA-Z_]*$/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 284 | 110 | $tag{ $self->get_id } = $tag; | |||||||||||||||||||||||||||||||
| 285 | 110 | return $self; | |||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||
| 287 | else { | ||||||||||||||||||||||||||||||||
| 288 | 0 | throw 'BadString' => "'$tag' is not valid for xml"; | |||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||
| 290 | 51 | ▶ | } | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||
| 292 | =item set_name() | ||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||
| 294 | Sets invocant name. | ||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||
| 296 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 297 | Title : set_name | ||||||||||||||||||||||||||||||||
| 298 | Usage : $obj->set_name($name); | ||||||||||||||||||||||||||||||||
| 299 | Function: Assigns an object's name. | ||||||||||||||||||||||||||||||||
| 300 | Returns : Modified object. | ||||||||||||||||||||||||||||||||
| 301 | Args : Argument must be a string. Ensure that this string is safe to use for | ||||||||||||||||||||||||||||||||
| 302 | whatever output format you want to use (this differs between xml and | ||||||||||||||||||||||||||||||||
| 303 | nexus, for example). | ||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||
| 305 | =cut | ||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||
| 307 | 9505 | ▶ | sub set_name : Clonable { | ||||||||||||||||||||||||||||||
|
Subroutine
set_name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 308 | 9505 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||
| 309 | 9505 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 310 | 9401 | return $self->set_attributes( 'label' => $name ); | |||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||
| 312 | else { | ||||||||||||||||||||||||||||||||
| 313 | 104 | return $self; | |||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||
| 315 | 51 | ▶ | } | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||
| 317 | =item set_attributes() | ||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||
| 319 | Assigns attributes for the element. | ||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||
| 321 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 322 | Title : set_attributes | ||||||||||||||||||||||||||||||||
| 323 | Usage : $obj->set_attributes( 'foo' => 'bar' ) | ||||||||||||||||||||||||||||||||
| 324 | Function: Sets the xml attributes for the object; | ||||||||||||||||||||||||||||||||
| 325 | Returns : $self | ||||||||||||||||||||||||||||||||
| 326 | Args : key/value pairs or a hash ref | ||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||
| 328 | =cut | ||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | 13995 | ▶ | sub set_attributes { | ||||||||||||||||||||||||||||||
|
Subroutine
set_attributes: called CC=9 SCAR=24.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 331 | 13995 | my $self = shift; | |||||||||||||||||||||||||||||||
| 332 | 13995 | my $id = $self->get_id; | |||||||||||||||||||||||||||||||
| 333 | 13995 | my %attrs; | |||||||||||||||||||||||||||||||
| 334 | 13995 | ▶ | if ( scalar @_ == 1 and ref $_[0] eq 'HASH' ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
scalar @_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||
| 335 | 0 | %attrs = %{ $_[0] }; | |||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||
| 337 | elsif ( scalar @_ % 2 == 0 ) { | ||||||||||||||||||||||||||||||||
| 338 | 13995 | %attrs = @_; | |||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||
| 340 | else { | ||||||||||||||||||||||||||||||||
| 341 | 0 | throw 'OddHash' => 'Arguments are not even key/value pairs'; | |||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||
| 343 | 13995 | ▶ | my $hash = $attributes{$id} || {}; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$attributes{$id} || {}
MC/DC100%1/1
$attributes{$id} || {}
$attributes{$id}
Truth table100%2/2
A
A= $attributes{$id}
| |||||||||||||||||||||||||||||||||
| 344 | 13995 | my $fully_qualified_attribute_regex = qr/^(.+?):(.+)/; | |||||||||||||||||||||||||||||||
| 345 | 13995 | for my $key ( keys %attrs ) { | |||||||||||||||||||||||||||||||
| 346 | 15490 | ▶ | if ( $key =~ $fully_qualified_attribute_regex ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 347 | 1496 | my ( $prefix, $attribute ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||
| 348 | 1496 | ▶ | if ( $prefix ne 'xmlns' and not exists $namespaces{$prefix} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$prefix ne "xmlns" and not exists $namespaces{$prefix}
MC/DC0%0/2
$prefix ne "xmlns" and not exists $namespaces{$prefix}
$prefix ne "xmlns"
not exists $namespaces{$prefix}
Truth table33%1/3
A and not(B)
A= $prefix ne "xmlns"B= not exists $namespaces{$prefix}
| |||||||||||||||||||||||||||||||||
| 349 | 0 | $logger->warn("Unbound attribute prefix '${prefix}'"); | |||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||
| 352 | 15490 | $hash->{$key} = $attrs{$key}; | |||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||
| 354 | 13995 | $attributes{$id} = $hash; | |||||||||||||||||||||||||||||||
| 355 | 13995 | return $self; | |||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||
| 358 | =item set_xml_id() | ||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||
| 360 | This method is usually only used internally, to store the xml id | ||||||||||||||||||||||||||||||||
| 361 | of an object as it is parsed out of a nexml file - this is for | ||||||||||||||||||||||||||||||||
| 362 | the purpose of round-tripping nexml info sets. | ||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||
| 364 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 365 | Title : set_xml_id | ||||||||||||||||||||||||||||||||
| 366 | Usage : $obj->set_xml_id('node345'); | ||||||||||||||||||||||||||||||||
| 367 | Function: Sets the xml id | ||||||||||||||||||||||||||||||||
| 368 | Returns : $self | ||||||||||||||||||||||||||||||||
| 369 | Args : An xml id (must be a valid xml NCName) | ||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||
| 371 | =cut | ||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||
| 373 | 1 | ▶ | sub set_xml_id { | ||||||||||||||||||||||||||||||
|
Subroutine
set_xml_id: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 374 | 1 | my ( $self, $id ) = @_; | |||||||||||||||||||||||||||||||
| 375 | 1 | ▶ | if ( $id =~ qr/^[a-zA-Z][a-zA-Z0-9\-_\.]*$/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 376 | 1 | $id{ $self->get_id } = $id; | |||||||||||||||||||||||||||||||
| 377 | 1 | $self->set_attributes( 'id' => $id, 'about' => "#$id" ); | |||||||||||||||||||||||||||||||
| 378 | 1 | return $self; | |||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||
| 380 | else { | ||||||||||||||||||||||||||||||||
| 381 | 0 | throw 'BadString' => "'$id' is not a valid xml NCName for $self"; | |||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||
| 385 | =item set_base_uri() | ||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||
| 387 | This utility method can be used to set the xml:base attribute, i.e. to specify | ||||||||||||||||||||||||||||||||
| 388 | a location for the object's XML serialization that potentially differs from | ||||||||||||||||||||||||||||||||
| 389 | the physical location of the containing document. | ||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||
| 391 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 392 | Title : set_base_uri | ||||||||||||||||||||||||||||||||
| 393 | Usage : $obj->set_base_uri('http://example.org'); | ||||||||||||||||||||||||||||||||
| 394 | Function: Sets the xml:base attribute | ||||||||||||||||||||||||||||||||
| 395 | Returns : $self | ||||||||||||||||||||||||||||||||
| 396 | Args : A URI string | ||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||
| 398 | =cut | ||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||
| 400 | 110 | ▶ | sub set_base_uri : Clonable { | ||||||||||||||||||||||||||||||
|
Subroutine
set_base_uri: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 401 | 110 | my ( $self, $uri ) = @_; | |||||||||||||||||||||||||||||||
| 402 | 110 | ▶ | if ( $uri ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 403 | 2 | $self->set_attributes( 'xml:base' => $uri ); | |||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||
| 405 | 110 | return $self; | |||||||||||||||||||||||||||||||
| 406 | 51 | ▶ | } | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||
| 408 | =item set_link() | ||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||
| 410 | This sets a clickable link, i.e. a url, for the object. This has no relation to | ||||||||||||||||||||||||||||||||
| 411 | the xml:base attribute, it is solely intended for serializations that | ||||||||||||||||||||||||||||||||
| 412 | allow clickable links, such as SVG or RSS. | ||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||
| 414 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 415 | Title : set_link | ||||||||||||||||||||||||||||||||
| 416 | Usage : $node->set_link($url); | ||||||||||||||||||||||||||||||||
| 417 | Function: Sets clickable link | ||||||||||||||||||||||||||||||||
| 418 | Returns : $self | ||||||||||||||||||||||||||||||||
| 419 | Args : url | ||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||
| 421 | =cut | ||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||
| 423 | 117 | ▶ | sub set_link : Clonable { | ||||||||||||||||||||||||||||||
|
Subroutine
set_link: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 424 | 117 | my ( $self, $url ) = @_; | |||||||||||||||||||||||||||||||
| 425 | 117 | ▶ | if ( $url ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 426 | 9 | my $id = $self->get_id; | |||||||||||||||||||||||||||||||
| 427 | 9 | $url{$id} = $url; | |||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||
| 429 | 117 | return $self; | |||||||||||||||||||||||||||||||
| 430 | 51 | ▶ | } | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||
| 432 | =item unset_attribute() | ||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||
| 434 | Removes specified attribute | ||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||
| 436 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 437 | Title : unset_attribute | ||||||||||||||||||||||||||||||||
| 438 | Usage : $obj->unset_attribute( 'foo' ) | ||||||||||||||||||||||||||||||||
| 439 | Function: Removes the specified xml attribute for the object | ||||||||||||||||||||||||||||||||
| 440 | Returns : $self | ||||||||||||||||||||||||||||||||
| 441 | Args : an attribute name | ||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||
| 443 | =cut | ||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | sub unset_attribute { | ||||||||||||||||||||||||||||||
|
Subroutine
unset_attribute: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 446 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 447 | 0 | my $attrs = $attributes{ $self->get_id }; | |||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | if ( $attrs and looks_like_instance( $attrs, 'HASH' ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attrs and &looks_like_instance($attrs, "HASH")
MC/DC0%0/2
$attrs and &looks_like_instance($attrs, "HASH")
$attrs
&looks_like_instance($attrs, "HASH")
Truth table0%0/3
A and B
A= $attrsB= &looks_like_instance($attrs, "HASH")
| |||||||||||||||||||||||||||||||||
| 449 | 0 | delete $attrs->{$_} for @_; | |||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||
| 451 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||
| 454 | =back | ||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||
| 456 | =head2 ACCESSORS | ||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||
| 458 | =over | ||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||
| 460 | =item get_namespaces() | ||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||
| 462 | Type : Accessor | ||||||||||||||||||||||||||||||||
| 463 | Title : get_namespaces | ||||||||||||||||||||||||||||||||
| 464 | Usage : my %ns = %{ $obj->get_namespaces }; | ||||||||||||||||||||||||||||||||
| 465 | Function: Retrieves the known namespaces | ||||||||||||||||||||||||||||||||
| 466 | Returns : A hash of prefix/namespace key/value pairs, or | ||||||||||||||||||||||||||||||||
| 467 | a single namespace if a single, optional | ||||||||||||||||||||||||||||||||
| 468 | prefix was provided as argument | ||||||||||||||||||||||||||||||||
| 469 | Args : Optional - a namespace prefix | ||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||
| 471 | =cut | ||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||
| 473 | 17790 | ▶ | sub get_namespaces { | ||||||||||||||||||||||||||||||
|
Subroutine
get_namespaces: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 474 | 17790 | my ( $self, $prefix ) = @_; | |||||||||||||||||||||||||||||||
| 475 | 17790 | ▶ | if ($prefix) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 476 | 2776 | return $namespaces{$prefix}; | |||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||
| 478 | else { | ||||||||||||||||||||||||||||||||
| 479 | 15014 | my %tmp_namespaces = %namespaces; | |||||||||||||||||||||||||||||||
| 480 | 15014 | return \%tmp_namespaces; | |||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||
| 484 | =item get_prefix_for_namespace() | ||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||
| 486 | Type : Accessor | ||||||||||||||||||||||||||||||||
| 487 | Title : get_prefix_for_namespace | ||||||||||||||||||||||||||||||||
| 488 | Usage : my $prefix = $obj->get_prefix_for_namespace('http://example.org/') | ||||||||||||||||||||||||||||||||
| 489 | Function: Retrieves the prefix for the argument namespace | ||||||||||||||||||||||||||||||||
| 490 | Returns : A prefix string | ||||||||||||||||||||||||||||||||
| 491 | Args : A namespace URI | ||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||
| 493 | =cut | ||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | sub get_prefix_for_namespace { | ||||||||||||||||||||||||||||||
|
Subroutine
get_prefix_for_namespace: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 496 | 0 | my ( $self, $ns_uri ) = @_; | |||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||
| 498 | # check argument | ||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | if ( not $ns_uri ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 500 | 0 | throw 'BadArgs' => "Need namespaces URI argument"; | |||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||
| 503 | # iterate over namespace/prefix pairs | ||||||||||||||||||||||||||||||||
| 504 | 0 | my $namespaces = $self->get_namespaces; | |||||||||||||||||||||||||||||||
| 505 | 0 | for my $prefix ( keys %{ $namespaces } ) { | |||||||||||||||||||||||||||||||
| 506 | 0 | ▶ | if ( $namespaces->{$prefix} eq $ns_uri ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 507 | 0 | return $prefix; | |||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||
| 511 | # warn user | ||||||||||||||||||||||||||||||||
| 512 | 0 | $logger->warn("No prefix for namespace $ns_uri"); | |||||||||||||||||||||||||||||||
| 513 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||
| 516 | =item get_meta() | ||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||
| 518 | Retrieves the metadata for the element. | ||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||
| 520 | Type : Accessor | ||||||||||||||||||||||||||||||||
| 521 | Title : get_meta | ||||||||||||||||||||||||||||||||
| 522 | Usage : my @meta = @{ $obj->get_meta }; | ||||||||||||||||||||||||||||||||
| 523 | Function: Retrieves the metadata for the element. | ||||||||||||||||||||||||||||||||
| 524 | Returns : An array ref of Bio::Phylo::NeXML::Meta objects | ||||||||||||||||||||||||||||||||
| 525 | Args : Optional: a list of CURIE predicates, in which case | ||||||||||||||||||||||||||||||||
| 526 | the returned objects will be those matching these | ||||||||||||||||||||||||||||||||
| 527 | predicates | ||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||
| 529 | =cut | ||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||
| 531 | 65920 | ▶ | sub get_meta { | ||||||||||||||||||||||||||||||
|
Subroutine
get_meta: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 532 | 65920 | my $self = shift; | |||||||||||||||||||||||||||||||
| 533 | 65920 | ▶ | my $metas = $meta{ $self->get_id } || []; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$meta{$self->get_id} || []
MC/DC100%1/1
$meta{$self->get_id} || []
$meta{$self->get_id}
Truth table100%2/2
A
A= $meta{$self->get_id}
| |||||||||||||||||||||||||||||||||
| 534 | 65920 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 535 | 50527 | my %predicates = map { $_ => 1 } @_; | |||||||||||||||||||||||||||||||
| 536 | 50527 | my @matches = grep { $predicates{$_->get_predicate} } @{ $metas }; | |||||||||||||||||||||||||||||||
| 537 | 50527 | return \@matches; | |||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||
| 539 | 15393 | return $metas; | |||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||
| 542 | =item get_meta_object() | ||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||
| 544 | Retrieves the metadata annotation object for the provided predicate | ||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||
| 546 | Type : Accessor | ||||||||||||||||||||||||||||||||
| 547 | Title : get_meta_object | ||||||||||||||||||||||||||||||||
| 548 | Usage : my $title = $obj->get_meta_object('dc:title'); | ||||||||||||||||||||||||||||||||
| 549 | Function: Retrieves the metadata annotation value for the object. | ||||||||||||||||||||||||||||||||
| 550 | Returns : An annotation value, i.e. the object of a triple | ||||||||||||||||||||||||||||||||
| 551 | Args : Required: a CURIE predicate for which the annotation | ||||||||||||||||||||||||||||||||
| 552 | value is returned | ||||||||||||||||||||||||||||||||
| 553 | Note : This method returns the object for the first annotation | ||||||||||||||||||||||||||||||||
| 554 | with the provided predicate. Keep this in mind when dealing | ||||||||||||||||||||||||||||||||
| 555 | with an object that has multiple annotations with the same | ||||||||||||||||||||||||||||||||
| 556 | predicate. | ||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||
| 558 | =cut | ||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||
| 560 | 49727 | ▶ | sub get_meta_object { | ||||||||||||||||||||||||||||||
|
Subroutine
get_meta_object: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 561 | 49727 | my ( $self, $predicate ) = @_; | |||||||||||||||||||||||||||||||
| 562 | 49727 | ▶ | throw 'BadArgs' => "No CURIE provided" unless $predicate; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 563 | 49727 | my ( $meta ) = @{ $self->get_meta($predicate) }; | |||||||||||||||||||||||||||||||
| 564 | 49727 | ▶ | if ( $meta ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 565 | 432 | return $meta->get_object; | |||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||
| 567 | else { | ||||||||||||||||||||||||||||||||
| 568 | 49295 | return undef; | |||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||
| 572 | =item get_tag() | ||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||
| 574 | Retrieves tag name for the element. | ||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||
| 576 | Type : Accessor | ||||||||||||||||||||||||||||||||
| 577 | Title : get_tag | ||||||||||||||||||||||||||||||||
| 578 | Usage : my $tag = $obj->get_tag; | ||||||||||||||||||||||||||||||||
| 579 | Function: Gets the xml tag name for the object; | ||||||||||||||||||||||||||||||||
| 580 | Returns : A tag name | ||||||||||||||||||||||||||||||||
| 581 | Args : None. | ||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||
| 583 | =cut | ||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||
| 585 | 1643 | ▶ | sub get_tag { | ||||||||||||||||||||||||||||||
|
Subroutine
get_tag: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 586 | 1643 | my $self = shift; | |||||||||||||||||||||||||||||||
| 587 | 1643 | ▶ | if ( my $tagstring = $tag{ $self->get_id } ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 588 | 32 | return $tagstring; | |||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||
| 590 | elsif ( looks_like_implementor $self, '_tag' ) { | ||||||||||||||||||||||||||||||||
| 591 | 1611 | return $self->_tag; | |||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||
| 593 | else { | ||||||||||||||||||||||||||||||||
| 594 | 0 | return ''; | |||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||
| 598 | =item get_name() | ||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||
| 600 | Gets invocant's name. | ||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||
| 602 | Type : Accessor | ||||||||||||||||||||||||||||||||
| 603 | Title : get_name | ||||||||||||||||||||||||||||||||
| 604 | Usage : my $name = $obj->get_name; | ||||||||||||||||||||||||||||||||
| 605 | Function: Returns the object's name. | ||||||||||||||||||||||||||||||||
| 606 | Returns : A string | ||||||||||||||||||||||||||||||||
| 607 | Args : None | ||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||
| 609 | =cut | ||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||
| 611 | 25149 | ▶ | sub get_name { | ||||||||||||||||||||||||||||||
|
Subroutine
get_name: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 612 | 25149 | my $self = shift; | |||||||||||||||||||||||||||||||
| 613 | 25149 | my $id = $self->get_id; | |||||||||||||||||||||||||||||||
| 614 | 25149 | ▶ | if ( !$attributes{$id} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 615 | 213 | $attributes{$id} = {}; | |||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||
| 617 | 25149 | ▶ | if ( defined $attributes{$id}->{'label'} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 618 | 24652 | return $attributes{$id}->{'label'}; | |||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||
| 620 | else { | ||||||||||||||||||||||||||||||||
| 621 | 497 | return ''; | |||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||
| 625 | =item get_xml_tag() | ||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||
| 627 | Retrieves tag string | ||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||
| 629 | Type : Accessor | ||||||||||||||||||||||||||||||||
| 630 | Title : get_xml_tag | ||||||||||||||||||||||||||||||||
| 631 | Usage : my $str = $obj->get_xml_tag; | ||||||||||||||||||||||||||||||||
| 632 | Function: Gets the xml tag for the object; | ||||||||||||||||||||||||||||||||
| 633 | Returns : A tag, i.e. pointy brackets | ||||||||||||||||||||||||||||||||
| 634 | Args : Optional: a true value, to close an empty tag | ||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||
| 636 | =cut | ||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||
| 638 | 0 | ▶ | sub get_xml_tag { | ||||||||||||||||||||||||||||||
|
Subroutine
get_xml_tag: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 639 | 0 | my ( $self, $closeme ) = @_; | |||||||||||||||||||||||||||||||
| 640 | 0 | my %attrs = %{ $self->get_attributes }; | |||||||||||||||||||||||||||||||
| 641 | 0 | my $tag = $self->get_tag; | |||||||||||||||||||||||||||||||
| 642 | 0 | my $xml = '<' . $tag; | |||||||||||||||||||||||||||||||
| 643 | 0 | for my $key ( keys %attrs ) { | |||||||||||||||||||||||||||||||
| 644 | 0 | $xml .= ' ' . $key . '="' . encode_entities($attrs{$key}) . '"'; | |||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||
| 646 | 0 | my $has_contents = 0; | |||||||||||||||||||||||||||||||
| 647 | 0 | my $meta = $self->get_meta; | |||||||||||||||||||||||||||||||
| 648 | 0 | ▶ | if ( @{$meta} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 649 | 0 | $xml .= '>'; # if not @{ $dictionaries }; | |||||||||||||||||||||||||||||||
| 650 | 0 | $xml .= $_->to_xml for @{$meta}; | |||||||||||||||||||||||||||||||
| 651 | 0 | $has_contents++; | |||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | if ($has_contents) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 654 | 0 | ▶ | $xml .= "</$tag>" if $closeme; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||
| 656 | else { | ||||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | $xml .= $closeme ? '/>' : '>'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||
| 659 | 0 | return $xml; | |||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||
| 662 | =item get_attributes() | ||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||
| 664 | Retrieves attributes for the element. | ||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||
| 666 | Type : Accessor | ||||||||||||||||||||||||||||||||
| 667 | Title : get_attributes | ||||||||||||||||||||||||||||||||
| 668 | Usage : my %attrs = %{ $obj->get_attributes }; | ||||||||||||||||||||||||||||||||
| 669 | Function: Gets the xml attributes for the object; | ||||||||||||||||||||||||||||||||
| 670 | Returns : A hash reference | ||||||||||||||||||||||||||||||||
| 671 | Args : None. | ||||||||||||||||||||||||||||||||
| 672 | Comments: throws ObjectMismatch if no linked taxa object | ||||||||||||||||||||||||||||||||
| 673 | can be found | ||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||
| 675 | =cut | ||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||
| 677 | 15014 | ▶ | my $add_namespaces_to_attributes = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.1
| |||||||||||||||||||||||||||||||||
| 678 | 15014 | my ( $self, $attrs ) = @_; | |||||||||||||||||||||||||||||||
| 679 | 15014 | my $i = 0; | |||||||||||||||||||||||||||||||
| 680 | 15014 | my $inside_to_xml_recursion = 0; | |||||||||||||||||||||||||||||||
| 681 | 15014 | ▶ | CHECK_RECURSE: while ( my @frame = caller($i) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 682 | 255409 | ▶ | if ( $frame[3] =~ m/::to_xml$/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 683 | 0 | $inside_to_xml_recursion++; | |||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | last CHECK_RECURSE if $inside_to_xml_recursion > 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||
| 686 | 255409 | $i++; | |||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||
| 688 | 15014 | ▶ | if ( $inside_to_xml_recursion <= 1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 689 | 15014 | my $tmp_namespaces = get_namespaces(); | |||||||||||||||||||||||||||||||
| 690 | 15014 | for my $ns ( keys %{$tmp_namespaces} ) { | |||||||||||||||||||||||||||||||
| 691 | 101797 | $attrs->{ 'xmlns:' . $ns } = $tmp_namespaces->{$ns}; | |||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||
| 694 | 15014 | return $attrs; | |||||||||||||||||||||||||||||||
| 695 | 51 | }; | |||||||||||||||||||||||||||||||
| 696 | 15168 | ▶ | my $flatten_attributes = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 697 | 15168 | my $self = shift; | |||||||||||||||||||||||||||||||
| 698 | 15168 | my $tempattrs = $attributes{ $self->get_id }; | |||||||||||||||||||||||||||||||
| 699 | 15168 | my $attrs; | |||||||||||||||||||||||||||||||
| 700 | 15168 | ▶ | if ($tempattrs) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 701 | 15136 | my %deref = %{$tempattrs}; | |||||||||||||||||||||||||||||||
| 702 | 15136 | $attrs = \%deref; | |||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||
| 704 | else { | ||||||||||||||||||||||||||||||||
| 705 | 32 | $attrs = {}; | |||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||
| 707 | 15168 | return $attrs; | |||||||||||||||||||||||||||||||
| 708 | 51 | }; | |||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||
| 710 | 15014 | ▶ | sub get_attributes { | ||||||||||||||||||||||||||||||
|
Subroutine
get_attributes: called CC=14 SCAR=38.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 711 | 15014 | my ( $self, $arg ) = @_; | |||||||||||||||||||||||||||||||
| 712 | 15014 | my $attrs = $flatten_attributes->($self); | |||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||
| 714 | # process the 'label' attribute: encode if there's anything there, | ||||||||||||||||||||||||||||||||
| 715 | # otherwise delete the attribute | ||||||||||||||||||||||||||||||||
| 716 | 15014 | ▶ | if ( $attrs->{'label'} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 717 | 0 | $attrs->{'label'} = encode_entities($attrs->{'label'}); | |||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||
| 719 | else { | ||||||||||||||||||||||||||||||||
| 720 | 15014 | delete $attrs->{'label'}; | |||||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||
| 723 | # process the id attribute: if it's not there, autogenerate it, unless | ||||||||||||||||||||||||||||||||
| 724 | # the object is explicitly not identifiable, in which case delete the | ||||||||||||||||||||||||||||||||
| 725 | # attribute | ||||||||||||||||||||||||||||||||
| 726 | 15014 | ▶ | if ( not $attrs->{'id'} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 727 | 15014 | $attrs->{'id'} = $self->get_xml_id; | |||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||
| 729 | 15014 | ▶ | if ( defined $self->is_identifiable and not $self->is_identifiable ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->is_identifiable and not $self->is_identifiable
MC/DC0%0/2
defined $self->is_identifiable and not $self->is_identifiable
defined $self->is_identifiable
not $self->is_identifiable
Truth table33%1/3
A and not(B)
A= defined $self->is_identifiableB= not $self->is_identifiable
| |||||||||||||||||||||||||||||||||
| 730 | 0 | delete $attrs->{'id'}; | |||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||
| 733 | # process the about attribute | ||||||||||||||||||||||||||||||||
| 734 | 15014 | ▶ | if ( not @{ $self->get_meta } and $attrs->{'about'} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not @{$self->get_meta;} and $attrs->{"about"}
MC/DC0%0/2
not @{$self->get_meta;} and $attrs->{"about"}
not @{$self->get_meta;}
$attrs->{"about"}
Truth table33%1/3
not(A) and B
A= not @{$self->get_meta;}B= $attrs->{"about"}
| |||||||||||||||||||||||||||||||||
| 735 | 0 | delete $attrs->{'about'}; | |||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||
| 738 | # set the otus attribute | ||||||||||||||||||||||||||||||||
| 739 | 15014 | ▶ | if ( $self->can('get_taxa') ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 740 | 0 | ▶ | if ( my $taxa = $self->get_taxa ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 741 | 0 | ▶ | $attrs->{'otus'} = $taxa->get_xml_id | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 742 | if looks_like_instance( $taxa, 'Bio::Phylo' ); | ||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||
| 744 | else { | ||||||||||||||||||||||||||||||||
| 745 | 0 | $logger->error("$self can link to a taxa element, but doesn't"); | |||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||
| 749 | # set the otu attribute | ||||||||||||||||||||||||||||||||
| 750 | 15014 | ▶ | if ( $self->can('get_taxon') ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 751 | 0 | ▶ | if ( my $taxon = $self->get_taxon ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 752 | 0 | $attrs->{'otu'} = $taxon->get_xml_id; | |||||||||||||||||||||||||||||||
| 753 | } | ||||||||||||||||||||||||||||||||
| 754 | else { | ||||||||||||||||||||||||||||||||
| 755 | 0 | $logger->info("No linked taxon found"); | |||||||||||||||||||||||||||||||
| 756 | 0 | delete $attrs->{'otu'}; | |||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||
| 760 | # add the namespace attributes unless explicitly supressed | ||||||||||||||||||||||||||||||||
| 761 | 15014 | ▶ | if ( not $self->is_ns_suppressed ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 762 | 15014 | $attrs = $add_namespaces_to_attributes->( $self, $attrs ) | |||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||
| 765 | # now either return the whole hash or just one value if a | ||||||||||||||||||||||||||||||||
| 766 | # key/attribute name was provided | ||||||||||||||||||||||||||||||||
| 767 | 15014 | ▶ | return $arg ? $attrs->{$arg} : $attrs; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 768 | } | ||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||
| 770 | =item get_xml_id() | ||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||
| 772 | Retrieves xml id for the element. | ||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||
| 774 | Type : Accessor | ||||||||||||||||||||||||||||||||
| 775 | Title : get_xml_id | ||||||||||||||||||||||||||||||||
| 776 | Usage : my $id = $obj->get_xml_id; | ||||||||||||||||||||||||||||||||
| 777 | Function: Gets the xml id for the object; | ||||||||||||||||||||||||||||||||
| 778 | Returns : An xml id | ||||||||||||||||||||||||||||||||
| 779 | Args : None. | ||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||
| 781 | =cut | ||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||
| 783 | 15125 | ▶ | sub get_xml_id { | ||||||||||||||||||||||||||||||
|
Subroutine
get_xml_id: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 784 | 15125 | my $self = shift; | |||||||||||||||||||||||||||||||
| 785 | 15125 | ▶ | if ( my $id = $id{ $self->get_id } ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 786 | 13593 | return $id; | |||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||
| 788 | else { | ||||||||||||||||||||||||||||||||
| 789 | 1532 | my $xml_id = $self->get_tag; | |||||||||||||||||||||||||||||||
| 790 | 1532 | my $obj_id = $self->get_id; | |||||||||||||||||||||||||||||||
| 791 | 1532 | $xml_id =~ s/^(.).+(.)$/$1$2$obj_id/; | |||||||||||||||||||||||||||||||
| 792 | 1532 | return $id{$obj_id} = $xml_id; | |||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||
| 796 | =item get_base_uri() | ||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||
| 798 | This utility method can be used to get the xml:base attribute, which specifies | ||||||||||||||||||||||||||||||||
| 799 | a location for the object's XML serialization that potentially differs from | ||||||||||||||||||||||||||||||||
| 800 | the physical location of the containing document. | ||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||
| 802 | If no xml:base attribute has been defined on the focal object, this method | ||||||||||||||||||||||||||||||||
| 803 | moves on, recursively, to containing objects (e.g. from node to tree to forest) | ||||||||||||||||||||||||||||||||
| 804 | until such time that a base URI has been found. | ||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||
| 806 | Type : Mutator | ||||||||||||||||||||||||||||||||
| 807 | Title : get_base_uri | ||||||||||||||||||||||||||||||||
| 808 | Usage : my $base = $obj->get_base_uri; | ||||||||||||||||||||||||||||||||
| 809 | Function: Gets the xml:base attribute | ||||||||||||||||||||||||||||||||
| 810 | Returns : A URI string | ||||||||||||||||||||||||||||||||
| 811 | Args : None | ||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||
| 813 | =cut | ||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||
| 815 | 111 | ▶ | sub get_base_uri { | ||||||||||||||||||||||||||||||
|
Subroutine
get_base_uri: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 816 | 111 | my $self = shift; | |||||||||||||||||||||||||||||||
| 817 | 111 | ▶ | while ( $self ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 818 | 154 | my $attrs = $flatten_attributes->($self); | |||||||||||||||||||||||||||||||
| 819 | 154 | ▶ | if ( my $base = $attrs->{'xml:base'} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 820 | 3 | $logger->info("Found xml:base attribute on $self: $base"); | |||||||||||||||||||||||||||||||
| 821 | 3 | return $base; | |||||||||||||||||||||||||||||||
| 822 | } | ||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||
| 824 | 151 | $logger->info("Traversing up to $self to locate xml:base"); | |||||||||||||||||||||||||||||||
| 825 | # we do this because node objects are contained inside their | ||||||||||||||||||||||||||||||||
| 826 | # parents, recursively, but node nexml elements aren't. it | ||||||||||||||||||||||||||||||||
| 827 | # would be inefficient to traverse all the parent nodes when, | ||||||||||||||||||||||||||||||||
| 828 | # logically, none of them could have an xml:base attribute | ||||||||||||||||||||||||||||||||
| 829 | # that could apply to the original invocant. in fact, doing | ||||||||||||||||||||||||||||||||
| 830 | # so could yield spurious results. | ||||||||||||||||||||||||||||||||
| 831 | 151 | ▶ | if ( $self->_type == _NODE_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 832 | 2 | $self = $self->get_tree; | |||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||
| 834 | else { | ||||||||||||||||||||||||||||||||
| 835 | 149 | $self = $self->_get_container; | |||||||||||||||||||||||||||||||
| 836 | } | ||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||
| 838 | 108 | $logger->info("No xml:base attribute was found anywhere"); | |||||||||||||||||||||||||||||||
| 839 | 108 | return undef; | |||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||
| 842 | =item get_link() | ||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||
| 844 | This returns a clickable link for the object. This has no relation to | ||||||||||||||||||||||||||||||||
| 845 | the xml:base attribute, it is solely intended for serializations that | ||||||||||||||||||||||||||||||||
| 846 | allow clickable links, such as SVG or RSS. | ||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||
| 848 | Type : Accessor | ||||||||||||||||||||||||||||||||
| 849 | Title : get_link | ||||||||||||||||||||||||||||||||
| 850 | Usage : my $link = $obj->get_link(); | ||||||||||||||||||||||||||||||||
| 851 | Function: Returns a clickable link | ||||||||||||||||||||||||||||||||
| 852 | Returns : url | ||||||||||||||||||||||||||||||||
| 853 | Args : NONE | ||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||
| 855 | =cut | ||||||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||||||
| 857 | 150 | ▶ | sub get_link { $url{ shift->get_id } } | ||||||||||||||||||||||||||||||
|
Subroutine
get_link: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||
| 859 | =item get_dom_elt() | ||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||
| 861 | Type : Serializer | ||||||||||||||||||||||||||||||||
| 862 | Title : get_dom_elt | ||||||||||||||||||||||||||||||||
| 863 | Usage : $obj->get_dom_elt | ||||||||||||||||||||||||||||||||
| 864 | Function: Generates a DOM element from the invocant | ||||||||||||||||||||||||||||||||
| 865 | Returns : a DOM element object (default XML::Twig) | ||||||||||||||||||||||||||||||||
| 866 | Args : DOM factory object | ||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||
| 868 | =cut | ||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||
| 870 | 0 | ▶ | sub get_dom_elt { | ||||||||||||||||||||||||||||||
|
Subroutine
get_dom_elt: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 871 | 0 | my ( $self, $dom ) = @_; | |||||||||||||||||||||||||||||||
| 872 | 0 | ▶ | $dom ||= Bio::Phylo::NeXML::DOM->get_dom; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$dom ||= "Bio::Phylo::NeXML::DOM"->get_dom
MC/DC0%0/2
$dom ||= "Bio::Phylo::NeXML::DOM"->get_dom
$dom
"Bio::Phylo::NeXML::DOM"->get_dom
Truth table0%0/3
A ||= B
A= $domB= "Bio::Phylo::NeXML::DOM"->get_dom
| |||||||||||||||||||||||||||||||||
| 873 | 0 | ▶ | unless ( looks_like_object $dom, _DOMCREATOR_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 874 | 0 | throw 'BadArgs' => 'DOM factory object not provided'; | |||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||
| 876 | 0 | my $elt = $dom->create_element( '-tag' => $self->get_tag ); | |||||||||||||||||||||||||||||||
| 877 | 0 | my %attrs = %{ $self->get_attributes }; | |||||||||||||||||||||||||||||||
| 878 | 0 | for my $key ( keys %attrs ) { | |||||||||||||||||||||||||||||||
| 879 | 0 | $elt->set_attributes( $key => $attrs{$key} ); | |||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||
| 881 | 0 | for my $meta ( @{ $self->get_meta } ) { | |||||||||||||||||||||||||||||||
| 882 | 0 | $elt->set_child( $meta->to_dom($dom) ); | |||||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||
| 885 | #my $dictionaries = $self->get_dictionaries; | ||||||||||||||||||||||||||||||||
| 886 | #if ( @{ $dictionaries } ) { | ||||||||||||||||||||||||||||||||
| 887 | # $elt->set_child( $_->to_dom($dom) ) for @{ $dictionaries }; | ||||||||||||||||||||||||||||||||
| 888 | #} | ||||||||||||||||||||||||||||||||
| 889 | 0 | ▶ | if ( looks_like_implementor $self, 'get_sets' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 890 | 0 | my $sets = $self->get_sets; | |||||||||||||||||||||||||||||||
| 891 | 0 | $elt->set_child( $_->to_dom($dom) ) for @{$sets}; | |||||||||||||||||||||||||||||||
| 892 | } | ||||||||||||||||||||||||||||||||
| 893 | 0 | return $elt; | |||||||||||||||||||||||||||||||
| 894 | } | ||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||
| 896 | =back | ||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||
| 898 | =head2 TESTS | ||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||
| 900 | =over | ||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||
| 902 | =item is_identifiable() | ||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||
| 904 | By default, all XMLWritable objects are identifiable when serialized, | ||||||||||||||||||||||||||||||||
| 905 | i.e. they have a unique id attribute. However, in some cases a serialized | ||||||||||||||||||||||||||||||||
| 906 | object may not have an id attribute (governed by the nexml schema). This | ||||||||||||||||||||||||||||||||
| 907 | method indicates whether that is the case. | ||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||
| 909 | Type : Test | ||||||||||||||||||||||||||||||||
| 910 | Title : is_identifiable | ||||||||||||||||||||||||||||||||
| 911 | Usage : if ( $obj->is_identifiable ) { ... } | ||||||||||||||||||||||||||||||||
| 912 | Function: Indicates whether IDs are generated | ||||||||||||||||||||||||||||||||
| 913 | Returns : BOOLEAN | ||||||||||||||||||||||||||||||||
| 914 | Args : NONE | ||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||
| 916 | =cut | ||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||
| 918 | 16568 | ▶ | sub is_identifiable { | ||||||||||||||||||||||||||||||
|
Subroutine
is_identifiable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 919 | 16568 | my $self = shift; | |||||||||||||||||||||||||||||||
| 920 | 16568 | return $identifiable{ $self->get_id }; | |||||||||||||||||||||||||||||||
| 921 | } | ||||||||||||||||||||||||||||||||
| 922 | 51 | *get_identifiable = \&is_identifiable; | |||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||||
| 924 | =item is_ns_suppressed() | ||||||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||||||
| 926 | Type : Test | ||||||||||||||||||||||||||||||||
| 927 | Title : is_ns_suppressed | ||||||||||||||||||||||||||||||||
| 928 | Usage : if ( $obj->is_ns_suppressed ) { ... } | ||||||||||||||||||||||||||||||||
| 929 | Function: Indicates whether namespace attributes should not | ||||||||||||||||||||||||||||||||
| 930 | be written on XML serialization | ||||||||||||||||||||||||||||||||
| 931 | Returns : BOOLEAN | ||||||||||||||||||||||||||||||||
| 932 | Args : NONE | ||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||
| 934 | =cut | ||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||
| 936 | 15125 | ▶ | sub is_ns_suppressed { | ||||||||||||||||||||||||||||||
|
Subroutine
is_ns_suppressed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 937 | 15125 | return $suppress_ns{ shift->get_id }; | |||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||
| 939 | 51 | *get_suppress_ns = \&is_ns_suppressed; | |||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||
| 941 | =item is_equal() | ||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||
| 943 | Tests whether the invocant and the argument are the same. Normally this is done | ||||||||||||||||||||||||||||||||
| 944 | by comparing object identifiers, but if the argument is not an object but a string | ||||||||||||||||||||||||||||||||
| 945 | then the string is taken to be a name with which to compare, e.g. | ||||||||||||||||||||||||||||||||
| 946 | $taxon->is_equal('Homo sapiens') | ||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||
| 948 | Type : Test | ||||||||||||||||||||||||||||||||
| 949 | Title : is_equal | ||||||||||||||||||||||||||||||||
| 950 | Usage : if ( $obj->is_equal($other) ) { ... } | ||||||||||||||||||||||||||||||||
| 951 | Function: Tests whether the invocant and the argument are the same | ||||||||||||||||||||||||||||||||
| 952 | Returns : BOOLEAN | ||||||||||||||||||||||||||||||||
| 953 | Args : Object to compare with, or a string representing a | ||||||||||||||||||||||||||||||||
| 954 | name to compare with the invocant's name | ||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||
| 956 | =cut | ||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||
| 958 | 3489 | ▶ | sub is_equal { | ||||||||||||||||||||||||||||||
|
Subroutine
is_equal: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 959 | 3489 | my ($self,$other) = @_; | |||||||||||||||||||||||||||||||
| 960 | 3489 | ▶ | return ref $other ? $self->SUPER::is_equal($other) : $self->get_name eq $other; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 961 | } | ||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||
| 963 | =back | ||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||
| 965 | =head2 SERIALIZERS | ||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||
| 967 | =over | ||||||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||||||
| 969 | =item to_xml() | ||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||
| 971 | Serializes invocant to XML. | ||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||
| 973 | Type : XML serializer | ||||||||||||||||||||||||||||||||
| 974 | Title : to_xml | ||||||||||||||||||||||||||||||||
| 975 | Usage : my $xml = $obj->to_xml; | ||||||||||||||||||||||||||||||||
| 976 | Function: Serializes $obj to xml | ||||||||||||||||||||||||||||||||
| 977 | Returns : An xml string | ||||||||||||||||||||||||||||||||
| 978 | Args : None | ||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||
| 980 | =cut | ||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||
| 982 | 0 | ▶ | sub to_xml { | ||||||||||||||||||||||||||||||
|
Subroutine
to_xml: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 983 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 984 | 0 | my $xml = ''; | |||||||||||||||||||||||||||||||
| 985 | 0 | ▶ | if ( $self->can('get_entities') ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 986 | 0 | for my $ent ( @{ $self->get_entities } ) { | |||||||||||||||||||||||||||||||
| 987 | 0 | ▶ | if ( looks_like_implementor $ent, 'to_xml' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 988 | 0 | $xml .= "\n" . $ent->to_xml; | |||||||||||||||||||||||||||||||
| 989 | } | ||||||||||||||||||||||||||||||||
| 990 | } | ||||||||||||||||||||||||||||||||
| 991 | 0 | $xml .= $self->sets_to_xml; | |||||||||||||||||||||||||||||||
| 992 | } | ||||||||||||||||||||||||||||||||
| 993 | 0 | ▶ | if ($xml) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 994 | 0 | $xml = $self->get_xml_tag . $xml . sprintf('</%s>', $self->get_tag); | |||||||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||||||
| 996 | else { | ||||||||||||||||||||||||||||||||
| 997 | 0 | $xml = $self->get_xml_tag(1); | |||||||||||||||||||||||||||||||
| 998 | } | ||||||||||||||||||||||||||||||||
| 999 | 0 | return $xml; | |||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||
| 1002 | =item to_dom() | ||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||
| 1004 | Type : Serializer | ||||||||||||||||||||||||||||||||
| 1005 | Title : to_dom | ||||||||||||||||||||||||||||||||
| 1006 | Usage : $obj->to_dom | ||||||||||||||||||||||||||||||||
| 1007 | Function: Generates a DOM subtree from the invocant and | ||||||||||||||||||||||||||||||||
| 1008 | its contained objects | ||||||||||||||||||||||||||||||||
| 1009 | Returns : a DOM element object (default: XML::Twig flavor) | ||||||||||||||||||||||||||||||||
| 1010 | Args : DOM factory object | ||||||||||||||||||||||||||||||||
| 1011 | Note : This is the generic function. It is redefined in the | ||||||||||||||||||||||||||||||||
| 1012 | classes below. | ||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||
| 1014 | =cut | ||||||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||||||
| 1016 | 0 | ▶ | sub to_dom { | ||||||||||||||||||||||||||||||
|
Subroutine
to_dom: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 1017 | 0 | my ( $self, $dom ) = @_; | |||||||||||||||||||||||||||||||
| 1018 | 0 | ▶ | $dom ||= Bio::Phylo::NeXML::DOM->get_dom; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$dom ||= "Bio::Phylo::NeXML::DOM"->get_dom
MC/DC0%0/2
$dom ||= "Bio::Phylo::NeXML::DOM"->get_dom
$dom
"Bio::Phylo::NeXML::DOM"->get_dom
Truth table0%0/3
A ||= B
A= $domB= "Bio::Phylo::NeXML::DOM"->get_dom
| |||||||||||||||||||||||||||||||||
| 1019 | 0 | ▶ | if ( looks_like_object $dom, _DOMCREATOR_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 1020 | 0 | my $elt = $self->get_dom_elt($dom); | |||||||||||||||||||||||||||||||
| 1021 | 0 | ▶ | if ( $self->can('get_entities') ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 1022 | 0 | for my $ent ( @{ $self->get_entities } ) { | |||||||||||||||||||||||||||||||
| 1023 | 0 | ▶ | if ( looks_like_implementor $ent, 'to_dom' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 1024 | 0 | $elt->set_child( $ent->to_dom($dom) ); | |||||||||||||||||||||||||||||||
| 1025 | } | ||||||||||||||||||||||||||||||||
| 1026 | } | ||||||||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||||||
| 1028 | 0 | return $elt; | |||||||||||||||||||||||||||||||
| 1029 | } | ||||||||||||||||||||||||||||||||
| 1030 | else { | ||||||||||||||||||||||||||||||||
| 1031 | 0 | throw 'BadArgs' => 'DOM factory object not provided'; | |||||||||||||||||||||||||||||||
| 1032 | } | ||||||||||||||||||||||||||||||||
| 1033 | } | ||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||
| 1035 | =item to_json() | ||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||
| 1037 | Serializes object to JSON string | ||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||
| 1039 | Type : Serializer | ||||||||||||||||||||||||||||||||
| 1040 | Title : to_json() | ||||||||||||||||||||||||||||||||
| 1041 | Usage : print $obj->to_json(); | ||||||||||||||||||||||||||||||||
| 1042 | Function: Serializes object to JSON string | ||||||||||||||||||||||||||||||||
| 1043 | Returns : String | ||||||||||||||||||||||||||||||||
| 1044 | Args : None | ||||||||||||||||||||||||||||||||
| 1045 | Comments: | ||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||
| 1047 | =cut | ||||||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||||||
| 1049 | 0 | ▶ | sub to_json { | ||||||||||||||||||||||||||||||
|
Subroutine
to_json: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 1050 | 0 | looks_like_class('Bio::Phylo::NeXML::XML2JSON')->new->convert( shift->to_xml ); | |||||||||||||||||||||||||||||||
| 1051 | } | ||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||
| 1053 | 0 | ▶ | sub _json_data { | ||||||||||||||||||||||||||||||
|
Subroutine
_json_data: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 1054 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 1055 | 0 | my %meta = map { $_->get_predicate => $_->get_object } @{ $self->get_meta }; | |||||||||||||||||||||||||||||||
| 1056 | 0 | my %result = %{ $self->SUPER::_json_data }; | |||||||||||||||||||||||||||||||
| 1057 | 0 | $result{$_} = $meta{$_} for keys %meta; | |||||||||||||||||||||||||||||||
| 1058 | 0 | ▶ | $result{'name'} = $self->get_name if $self->get_name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 1059 | 0 | ▶ | $result{'link'} = $self->get_link if $self->get_link; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 1060 | 0 | return \%result; | |||||||||||||||||||||||||||||||
| 1061 | } | ||||||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||||||
| 1063 | =item to_cdao() | ||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||
| 1065 | Serializes object to CDAO RDF/XML string | ||||||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||||||
| 1067 | Type : Serializer | ||||||||||||||||||||||||||||||||
| 1068 | Title : to_cdao() | ||||||||||||||||||||||||||||||||
| 1069 | Usage : print $obj->to_cdao(); | ||||||||||||||||||||||||||||||||
| 1070 | Function: Serializes object to CDAO RDF/XML string | ||||||||||||||||||||||||||||||||
| 1071 | Returns : String | ||||||||||||||||||||||||||||||||
| 1072 | Args : None | ||||||||||||||||||||||||||||||||
| 1073 | Comments: | ||||||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||||||
| 1075 | =cut | ||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||
| 1077 | 0 | ▶ | sub to_cdao { | ||||||||||||||||||||||||||||||
|
Subroutine
to_cdao: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 1078 | 0 | return unparse( | |||||||||||||||||||||||||||||||
| 1079 | '-phylo' => shift, | ||||||||||||||||||||||||||||||||
| 1080 | '-format' => 'cdao', | ||||||||||||||||||||||||||||||||
| 1081 | ); | ||||||||||||||||||||||||||||||||
| 1082 | } | ||||||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||||||
| 1084 | 25006 | ▶ | sub _cleanup : Destructor { | ||||||||||||||||||||||||||||||
|
Subroutine
_cleanup: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||
| 1085 | 25006 | my $self = shift; | |||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||
| 1087 | # this deserves an explanation. the issue is as follows: for the package | ||||||||||||||||||||||||||||||||
| 1088 | # bio-phylo-megatree we have node objects that are persisted in a database | ||||||||||||||||||||||||||||||||
| 1089 | # and accessed through an object-relational mapping provided by DBIx::Class. | ||||||||||||||||||||||||||||||||
| 1090 | # these node objects are created and destroyed on the fly as a set of node | ||||||||||||||||||||||||||||||||
| 1091 | # records (i.e. a tree) is traversed. this is the whole point of the package, | ||||||||||||||||||||||||||||||||
| 1092 | # because it means large trees don't ever have to be kept in memory. however, | ||||||||||||||||||||||||||||||||
| 1093 | # as a consequence, every time one of those ORM-backed nodes goes out of scope, | ||||||||||||||||||||||||||||||||
| 1094 | # this destructor is called and all the @fields are cleaned up again. this | ||||||||||||||||||||||||||||||||
| 1095 | # precludes computation and caching of node coordinates (or any other semantic | ||||||||||||||||||||||||||||||||
| 1096 | # annotation) on such ORM-backed objects. the terrible, terrible fix for now is | ||||||||||||||||||||||||||||||||
| 1097 | # to just assume that i) these annotations need to stay alive ii) we're not going | ||||||||||||||||||||||||||||||||
| 1098 | # to have ID clashes (!!!!!), so iii) we just don't clean up after ourselves. | ||||||||||||||||||||||||||||||||
| 1099 | # as a note to my future self: it would be a good idea to have a triple store-like | ||||||||||||||||||||||||||||||||
| 1100 | # table to store the annotations, so they are persisted in the same way as the | ||||||||||||||||||||||||||||||||
| 1101 | # node objects, bypassing this malarkey. | ||||||||||||||||||||||||||||||||
| 1102 | 25006 | ▶ | if ( not $self->isa('DBIx::Class::Core') ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 1103 | 25006 | my $id = $self->get_id; | |||||||||||||||||||||||||||||||
| 1104 | 25006 | for my $field (@fields) { | |||||||||||||||||||||||||||||||
| 1105 | 175042 | delete $field->{$id}; | |||||||||||||||||||||||||||||||
| 1106 | } | ||||||||||||||||||||||||||||||||
| 1107 | } | ||||||||||||||||||||||||||||||||
| 1108 | 51 | ▶ | } | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||||||
| 1110 | =back | ||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||
| 1112 | =cut | ||||||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||||||
| 1114 | # podinherit_insert_token | ||||||||||||||||||||||||||||||||
| 1115 | |||||||||||||||||||||||||||||||||
| 1116 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||||||
| 1118 | There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo> | ||||||||||||||||||||||||||||||||
| 1119 | for any user or developer questions and discussions. | ||||||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||||||
| 1121 | Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>. | ||||||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||||||
| 1123 | =head1 CITATION | ||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||
| 1125 | If you use Bio::Phylo in published research, please cite it: | ||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||
| 1127 | B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> | ||||||||||||||||||||||||||||||||
| 1128 | and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. | ||||||||||||||||||||||||||||||||
| 1129 | I<BMC Bioinformatics> B<12>:63. | ||||||||||||||||||||||||||||||||
| 1130 | L<http://dx.doi.org/10.1186/1471-2105-12-63> | ||||||||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||||||
| 1132 | =cut | ||||||||||||||||||||||||||||||||
| 1133 | |||||||||||||||||||||||||||||||||
| 1134 | } | ||||||||||||||||||||||||||||||||
| 1135 | 51 | 1; | |||||||||||||||||||||||||||||||