| 1 | # $Id: TagTree.pm 11693 2007-09-17 20:54:04Z cjfields $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # BioPerl module for Bio::Annotation::TagTree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Cared for Chris Fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # You may distribute this module under the same terms as perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # Refer to the Perl Artistic License (see the license accompanying this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # software package, or see http://www.perl.com/language/misc/Artistic.html) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # for the terms under which you may use, modify, and redistribute this module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | Bio::Annotation::TagTree - AnnotationI with tree-like hierarchal key-value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | relationships ('structured tags') that can be represented as simple text. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | use Bio::Annotation::TagTree; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | use Bio::Annotation::Collection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | my $col = Bio::Annotation::Collection->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # data structure can be an array reference with a data structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # corresponding to that defined by Data::Stag: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | my $sv = Bio::Annotation::TagTree->new(-tagname => 'mytag1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | -value => $data_structure); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | $col->add_Annotation($sv); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # regular text passed is parsed based on the tagformat(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | my $sv2 = Bio::Annotation::TagTree->new(-tagname => 'mytag2', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | -tagformat => 'xml', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | -value => $xmltext); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | $col->add_Annotation($sv2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | This takes tagged data values and stores them in a hierarchal structured | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | element-value hierarchy (complements of Chris Mungall's Data::Stag module). Data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | can then be represented as text using a variety of output formats (indention, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | itext, xml, spxr). Furthermore, the data structure can be queried using various | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | means. See L<Data::Stag> for details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | Data passed in using value() or the '-value' parameter upon instantiation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | can either be: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1) an array reference corresponding to the data structure for Data::Stag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2) a text string in 'xml', 'itext', 'spxr', or 'indent' format. The default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | format is 'xml'; this can be changed using tagformat() prior to using value() or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | by passing in the proper format using '-tagformat' upon instantiation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3) another Bio::Annotation::TagTree or Data::Stag node instance. In both cases | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | a deep copy (duplicate) of the instance is generated. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | Beyond checking for an array reference no format guessing occurs (so, for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | roundtrip tests ensure that the IO formats correspond). For now, we recommend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | when using text input to set tagformat() to one of these formats prior to data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | loading to ensure the proper Data::Stag parser is selected. After data loading, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | the tagformat() can be changed to change the text string format returned by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | value(). (this may be rectified in the future) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | This Annotation type is fully BioSQL compatible and could be considered a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | temporary replacement for nested Bio::Annotation::Collections, at least until | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | BioSQL and bioperl-db can support nested annotation collections. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =head2 Mailing Lists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | Bioperl modules. Send your comments and suggestions preferably to one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | of the Bioperl mailing lists. Your participation is much appreciated. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | =head2 Support | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | the bugs and their resolution. Bug reports can be submitted via | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | or the web: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | Chris Fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | =head1 APPENDIX | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | The rest of the documentation details each of the object methods. Internal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | methods are usually preceded with a _ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # Let the code begin... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | package Bio::Annotation::TagTree; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 11 | $Bio::Annotation::TagTree::VERSION = '1.7.8'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Object preamble - inherits from Bio::Root::Root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 11 | ▶ | use base qw(Bio::Annotation::SimpleValue); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 11 | ▶ | use Data::Stag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | Title : new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | Usage : my $sv = Bio::Annotation::TagTree->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | Function: Instantiate a new TagTree object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | Returns : Bio::Annotation::TagTree object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | Args : -value => $value to initialize the object data field [optional] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | -tagname => $tag to initialize the tagname [optional] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | -tagformat => format for output [optional] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | (types 'xml', 'itext', 'sxpr', 'indent', default = 'itext') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | -node => Data::Stag node or Bio::Annotation::TagTree instance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 55 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 55 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 55 | my $self = $class->SUPER::new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 55 | my ( $node, $value, $tag, $format, $verbose ) = $self->_rearrange( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | NODE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | VALUE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | TAGNAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | TAGFORMAT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | VERBOSE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | @args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 55 | ▶ | $self->throw("Cant use both node and value; mutually exclusive") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $node and defined $value
MC/DC0%0/2
defined $node and defined $value
defined $node
defined $value
Truth table33%1/3
A and B
A= defined $nodeB= defined $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | if defined $node && defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 55 | ▶ | defined $tag && $self->tagname($tag); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 55 | ▶ | $format ||= 'itext'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$format ||= "itext"
MC/DC0%0/1
$format ||= "itext"
$format
Truth table50%1/2
A
A= $format
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 55 | $self->tagformat($format); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 55 | ▶ | defined $value && $self->value($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 55 | ▶ | defined $node && $self->node($node); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 55 | ▶ | defined $verbose && $self->verbose($verbose); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 55 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | =head1 AnnotationI implementing functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | =head2 as_text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | Title : as_text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | Usage : my $text = $obj->as_text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | Function: return the string "Value: $v" where $v is the value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | Returns : string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | Args : none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub as_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_text: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | return "TagTree: " . $self->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | =head2 display_text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | Title : display_text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | Usage : my $str = $ann->display_text(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | Function: returns a string. Unlike as_text(), this method returns a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | formatted as would be expected for the specific implementation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | One can pass a callback as an argument which allows custom text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | generation; the callback is passed the current instance and any text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | returned | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | Example : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | Returns : a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | Args : [optional] callback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | my $DEFAULT_CB = sub { $_[0]->value || '' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub display_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
display_text: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my ( $self, $cb ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | $cb ||= $DEFAULT_CB; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$cb ||= $DEFAULT_CB
MC/DC0%0/2
$cb ||= $DEFAULT_CB
$cb
$DEFAULT_CB
Truth table0%0/3
A ||= B
A= $cbB= $DEFAULT_CB
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | $self->throw("Callback must be a code reference") if ref $cb ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return $cb->($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | =head2 hash_tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | Title : hash_tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | Usage : my $hashtree = $value->hash_tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | Function: For supporting the AnnotationI interface just returns the value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | as a hashref with the key 'value' pointing to the value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | Maybe reimplement using Data::Stag::hash()? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | Returns : hashrf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | Args : none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 11 | ▶ | sub hash_tree { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hash_tree: not called CC=1 SCAR=3.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $h = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $h->{'value'} = $self->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | =head2 tagname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | Title : tagname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | Usage : $obj->tagname($newval) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | Function: Get/set the tagname for this annotation value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | Setting this is optional. If set, it obviates the need to provide | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | a tag to AnnotationCollection when adding this object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | Example : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | Returns : value of tagname (a scalar) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | Args : new value (a scalar, optional) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 69 | ▶ | sub tagname { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tagname: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 69 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 69 | ▶ | if ( defined $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 50 | $self->{'tagname'} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 69 | return $self->{'tagname'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | =head1 Specific accessors for TagTree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | =head2 value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | Title : value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | Usage : $obj->value($newval) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | Function: Get/set the value for this annotation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | Returns : value of value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | Args : newvalue (optional) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 76 | ▶ | sub value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 76 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # set mode? This resets the entire tagged database | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 76 | my $format = $self->tagformat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 76 | ▶ | if ($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 53 | ▶ | if ( ref $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 52 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # note the tagname() is not used here; it is only used for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # storing this AnnotationI in the annotation collection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 48 | eval { $self->{db} = Data::Stag->nodify($value) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # assuming this is blessed; passing on to node() and copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 4 | $self->node( $value, 'copy' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # not trying to guess here for now; we go by the tagformat() setting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | my $h = Data::Stag->getformathandler($format); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | eval { $self->{db} = Data::Stag->from( $format . 'str', $value ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 53 | ▶ | $self->throw("Data::Stag error:\n$@") if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # get mode? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # How do we return a data structure? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # for now, we use the output (if there is a Data::Stag node present) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # may need to run an eval {} to catch Data::Stag output errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 76 | $self->node->$format; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | =head2 tagformat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | Title : tagformat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | Usage : $obj->tagformat($newval) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | Function: Get/set the output tag format for this annotation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | Returns : value of tagformat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | Args : newvalue (optional) - format for the data passed into value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | must be of values 'xml', 'indent', 'sxpr', 'itext', 'perl' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 11 | my %IS_VALID_FORMAT = map { $_ => 1 } qw(xml indent sxpr itext); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 134 | ▶ | sub tagformat { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tagformat: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 134 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 134 | ▶ | if ( defined $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | $self->throw( "$value is not a valid format; valid format types:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | . join( ',', map { "'$_'" } keys %IS_VALID_FORMAT ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 58 | ▶ | if !exists $IS_VALID_FORMAT{$value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 58 | $self->{'tagformat'} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 134 | return $self->{'tagformat'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | =head2 node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | Title : node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | Usage : $obj->node() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | Function: Get/set the topmost Data::Stag node used for this annotation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | Returns : Data::Stag node implementation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | (default is Data::Stag::StagImpl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | Args : (optional) Data::Stag node implementation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | (optional)'copy' => flag to create a copy of the node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 115 | ▶ | sub node { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
node: called CC=10 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 115 | my ( $self, $value, $copy ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 115 | ▶ | if ( defined $value && ref $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $value and ref $value
MC/DC50%1/2
defined $value and ref $value
defined $value
ref $value
Truth table66%2/3
A and B
A= defined $valueB= ref $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 6 | ▶ | $self->{'db'} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition50%3/6
$copy and $copy eq "copy"
$copy and $copy eq "copy"
MC/DC50%1/2
$copy and $copy eq "copy"
$copy
$copy eq "copy"
MC/DC0%0/2
$copy and $copy eq "copy"
$copy
$copy eq "copy"
Truth table66%2/3
A and B
A= $copyB= $copy eq "copy"
Truth table33%1/3
A and B
A= $copyB= $copy eq "copy"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | $value->isa('Data::Stag::StagI') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | ? ( $copy && $copy eq 'copy' ? $value->duplicate : $value ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | : $value->isa('Bio::Annotation::TagTree') ? ( $copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | && $copy eq 'copy' ? $value->node->duplicate : $value->node ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | : $self->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 'Object must be Data::Stag::StagI or Bio::Annotation::TagTree'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # lazily create Data::Stag instance if not present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 115 | ▶ | if (!$self->{'db'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 4 | $self->{'db'} = Data::Stag->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 115 | return $self->{'db'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | =head2 Data::Stag convenience methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | Because Data::Stag uses blessed arrays and the core Bioperl class uses blessed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | hashes, TagTree uses an internal instance of a Data::Stag node for data storage. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | Therefore the following methods actually delegate to the Data:::Stag internal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | instance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | For consistency (since one could recursively check child nodes), methods retain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | the same names as Data::Stag. Also, no 'magic' (AUTOLOAD'ed) methods are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | employed, simply b/c full-fledged Data::Stag functionality can be attained by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | grabbing the Data::Stag instance using node(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | =head2 element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | Title : element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | Usage : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | Function: Returns the element name (key name) for this node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | Example : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | Returns : scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | Args : none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | sub element { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
element: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | return $self->node->element; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | =head2 data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | Title : data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | Usage : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | Function: Returns the data structure (array ref) for this node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | Example : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | Returns : array ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | Args : none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | sub data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | return $self->node->data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | =head2 children | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | Title : children | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | Usage : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | Function: Get the top-level array of Data::Stag nodes or (if the top level is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | a terminal node) a scalar value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | This is similar to StructuredValue's get_values() method, with the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | key difference being instead of array refs and scalars you get either | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | Data::Stag nodes or the value for this particular node. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | For consistency (since one could recursively check nodes), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | we use the same method name as Data::Stag children(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | Example : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | Returns : an array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | Args : none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 6 | ▶ | sub children { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
children: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 6 | return $self->node->children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | =head2 subnodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | Title : subnodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | Usage : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | Function: Get the top-level array of Data::Stag nodes. Unlike children(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | this only returns an array of nodes (if this is a terminal node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | no value is returned) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | Example : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | Returns : an array of nodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | Args : none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | sub subnodes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subnodes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | return $self->node->subnodes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | =head2 get | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | Title : get | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | Usage : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | Function: Returns the nodes or value for the named element or path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | Example : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | Returns : returns array of nodes or a scalar (if node is terminal) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | dependent on wantarray | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | Args : none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | my ( $self, @vals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | return $self->node->get(@vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | =head2 find | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | Title : find | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | Usage : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | Function: Recursively searches for and returns the nodes or values for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | named element or path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | Example : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | Returns : returns array of nodes or scalars (for terminal nodes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | Args : none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | sub find { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my ( $self, @vals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | return $self->node->find(@vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | =head2 findnode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | Title : findnode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | Usage : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | Function: Recursively searches for and returns a list of nodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | of the given element path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | Example : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | Returns : returns array of nodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | Args : none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 6 | ▶ | sub findnode { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
findnode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 6 | my ( $self, @vals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 6 | return $self->node->findnode(@vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | =head2 findval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | Title : findval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | Usage : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | Function: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | Example : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | Returns : returns array of nodes or values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | Args : none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 4 | ▶ | sub findval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
findval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 4 | my ( $self, @vals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 4 | return $self->node->findval(@vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | =head2 addchild | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | Title : addchild | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | Usage : $struct->addchild(['name' => [['foo'=> 'bar1']]]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | Function: add new child node to the current node. One can pass in a node, TagTree, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | or data structure; for instance, in the above, this would translate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | to (in XML): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | <name> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | <foo>bar1</foo> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | </name> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | Returns : node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | Args : first arg = element name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | all other args are added as tag-value pairs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | sub addchild { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addchild: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | my ( $self, @vals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | # check for element tag first (if no element, must be empty Data::Stag node) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | if ( !$self->element ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | # try to do the right thing; if more than one element, wrap in array ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | @vals > 1 ? $self->value( \@vals ) : $self->value( $vals[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | return $self->{db}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | elsif ( !$self->node->ntnodes ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | # if this is a terminal node, can't add to it (use set?) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | $self->throw("Can't add child to node; only terminal node is present!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | return $self->node->addchild(@vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | =head2 add | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | Title : add | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | Usage : $struct->add('foo', 'bar1', 'bar2', 'bar3'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | Function: add tag-value nodes to the current node. In the above, this would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | translate to (in XML): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | <foo>bar1</foo> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | <foo>bar2</foo> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | <foo>bar3</foo> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | Returns : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | Args : first arg = element name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | all other args are added as tag-value pairs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | my ( $self, @vals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | # check for empty object and die for now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | if ( !$self->node->element ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | $self->throw("Can't add to terminal element!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | return $self->node->add(@vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | =head2 set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | Title : set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | Usage : $struct->set('foo','bar'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | Function: sets a single tag-value pair in the current node. Note this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | differs from add() in that this replaces any data already present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | Returns : node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | Args : first arg = element name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | all other args are added as tag-value pairs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | my ( $self, @vals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | # check for empty object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | if ( !$self->node->element ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | $self->throw("Can't add to tree; empty tree!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | return $self->node->set(@vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | =head2 unset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | Title : unset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | Usage : $struct->unset('foo'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | Function: unsets all key-value pairs of the passed element from the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | current node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | Returns : node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | Args : element name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | sub unset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | my ( $self, @vals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | return $self->node->unset(@vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | =head2 free | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | Title : free | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | Usage : $struct->free | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | Function: removes all data from the current node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | Returns : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | Args : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | sub free { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
free: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | return $self->node->free; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | =head2 hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | Title : hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | Usage : $struct->hash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | Function: turns the tag-value tree into a hash, all data values are array refs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | Returns : hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | Args : first arg = element name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | all other args are added as tag-value pairs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | ▶ | sub hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hash: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | return $self->node->hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | =head2 pairs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | Title : pairs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | Usage : $struct->pairs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | Function: turns the tag-value tree into a hash, all data values are scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | Returns : hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | Args : first arg = element name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | all other args are added as tag-value pairs, note that duplicates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | will be lost | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 4 | ▶ | sub pairs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pairs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 4 | return $self->node->pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | =head2 qmatch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | Title : qmatch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | Usage : @persons = $s->qmatch('person', ('name'=>'fred')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | Function : returns all elements in the node tree which match the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | element name and the key-value pair | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | Returns : Array of nodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | Args : return-element str, match-element str, match-value str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | ▶ | sub qmatch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
qmatch: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | my ( $self, @vals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | return $self->node->qmatch(@vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | =head2 tnodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | Title : tnodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | Usage : @termini = $s->tnodes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | Function : returns all terminal nodes below this node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | Returns : Array of nodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | Args : return-element str, match-element str, match-value str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | sub tnodes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tnodes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | return $self->node->tnodes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | =head2 ntnodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | Title : ntnodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | Usage : @termini = $s->ntnodes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | Function : returns all nonterminal nodes below this node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | Returns : Array of nodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | Args : return-element str, match-element str, match-value str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | ▶ | sub ntnodes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ntnodes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | return $self->node->ntnodes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | =head2 StructureValue-like methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | =head2 get_all_values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | Title : get_all_values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | Usage : @termini = $s->get_all_values; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | Function : returns all terminal node values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | Returns : Array of values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | Args : return-element str, match-element str, match-value str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | This is meant to emulate the values one would get from StructureValue's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | get_all_values() method. Note, however, using this method dissociates the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | tag-value relationship (i.e. you only get the value list, no elements) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 4 | ▶ | sub get_all_values { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_values: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 4 | my @kids = $self->children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 4 | my @vals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 4 | ▶ | while ( my $val = shift @kids ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 92 | ▶ | ( ref $val ) ? push @kids, $val->children : push @vals, $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 4 | return @vals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||