| 1 | package Bio::Phylo::NeXML::DOM::Document; | ||
| 2 | use strict; | ||
| 3 | use Bio::Phylo::Util::Exceptions 'throw'; | ||
| 4 | use Bio::Phylo::Util::CONSTANT qw'_DOCUMENT_ /looks_like/'; | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Bio::Phylo::NeXML::DOM::Document - XML DOM Abstract class for | ||
| 9 | flexible document object model implementation | ||
| 10 | |||
| 11 | =head1 SYNOPSIS | ||
| 12 | |||
| 13 | Not used directly. | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | This module describes an abstract implementation of a DOM document as | ||
| 18 | expected by Bio::Phylo. The methods here must be overridden in any | ||
| 19 | concrete implementation. The idea is that different implementations | ||
| 20 | use a particular XML DOM package, binding the methods here to | ||
| 21 | analogous package methods. | ||
| 22 | |||
| 23 | This set of methods is intentionally minimal. The concrete instances | ||
| 24 | of this class should inherit both from DocumentI and the underlying XML DOM | ||
| 25 | object class, so that package-specific methods can be directly | ||
| 26 | accessed from the instantiated object. | ||
| 27 | |||
| 28 | =head1 AUTHOR | ||
| 29 | |||
| 30 | Mark A. Jensen - maj -at- fortinbras -dot- us | ||
| 31 | |||
| 32 | =cut | ||
| 33 | |||
| 34 | =head2 Constructor | ||
| 35 | |||
| 36 | =over | ||
| 37 | |||
| 38 | =item new() | ||
| 39 | |||
| 40 | Type : Constructor | ||
| 41 | Title : new | ||
| 42 | Usage : $doc = Bio::Phylo::NeXML::DOM::Document->new(@args) | ||
| 43 | Function: Create a Document object using the underlying package | ||
| 44 | Returns : Document object or undef on fail | ||
| 45 | Args : Package-specific arguments | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | sub new { | ||
| 50 | my $class = shift; | ||
| 51 | if ( my %args = looks_like_hash @_ ) { | ||
| 52 | $class = __PACKAGE__ . '::' . ucfirst( lc( $args{'-format'} ) ); | ||
| 53 | delete $args{'-format'}; | ||
| 54 | return looks_like_class($class)->new(%args); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | =item parse_document() | ||
| 59 | |||
| 60 | Type : Factory method | ||
| 61 | Title : parse_document | ||
| 62 | Usage : $doc = $dom->parse_document($text) | ||
| 63 | Function: Create a new XML DOM document from XML text | ||
| 64 | Returns : DOM document | ||
| 65 | Args : An XML String | ||
| 66 | |||
| 67 | =cut | ||
| 68 | |||
| 69 | sub parse_document { | ||
| 70 | throw 'NotImplemented' => "Can't call 'parse_document' on interface"; | ||
| 71 | } | ||
| 72 | |||
| 73 | =back | ||
| 74 | |||
| 75 | =cut | ||
| 76 | |||
| 77 | =head2 Document property accessors/mutators | ||
| 78 | |||
| 79 | =over | ||
| 80 | |||
| 81 | =item set_encoding() | ||
| 82 | |||
| 83 | Type : Mutator | ||
| 84 | Title : set_encoding | ||
| 85 | Usage : $doc->set_encoding($enc) | ||
| 86 | Function: Set encoding for document | ||
| 87 | Returns : True on success | ||
| 88 | Args : Encoding descriptor as string | ||
| 89 | |||
| 90 | =cut | ||
| 91 | |||
| 92 | sub set_encoding { | ||
| 93 | throw 'NotImplemented' => "Can't call 'set_encoding' on interface"; | ||
| 94 | } | ||
| 95 | |||
| 96 | =item get_encoding() | ||
| 97 | |||
| 98 | Type : Accessor | ||
| 99 | Title : get_encoding | ||
| 100 | Usage : $doc->get_encoding() | ||
| 101 | Function: Get encoding for document | ||
| 102 | Returns : Encoding descriptor as string | ||
| 103 | Args : none | ||
| 104 | |||
| 105 | =cut | ||
| 106 | |||
| 107 | sub get_encoding { | ||
| 108 | throw 'NotImplemented' => "Can't call 'get_encoding' on interface"; | ||
| 109 | } | ||
| 110 | |||
| 111 | =item set_root() | ||
| 112 | |||
| 113 | Type : Mutator | ||
| 114 | Title : set_root | ||
| 115 | Usage : $doc->set_root($elt) | ||
| 116 | Function: Set the document's root element | ||
| 117 | Returns : True on success | ||
| 118 | Args : Element object | ||
| 119 | |||
| 120 | =cut | ||
| 121 | |||
| 122 | sub set_root { | ||
| 123 | throw 'NotImplemented' => "Can't call 'set_root' on interface"; | ||
| 124 | } | ||
| 125 | |||
| 126 | =item get_root() | ||
| 127 | |||
| 128 | Type : Accessor | ||
| 129 | Title : get_root | ||
| 130 | Usage : $doc->get_root() | ||
| 131 | Function: Get the document's root element | ||
| 132 | Returns : Element object or undef if DNE | ||
| 133 | Args : none | ||
| 134 | |||
| 135 | =cut | ||
| 136 | |||
| 137 | sub get_root { | ||
| 138 | throw 'NotImplemented' => "Can't call 'get_root' on interface"; | ||
| 139 | } | ||
| 140 | |||
| 141 | =back | ||
| 142 | |||
| 143 | =cut | ||
| 144 | |||
| 145 | =head2 Document element accessors | ||
| 146 | |||
| 147 | =over | ||
| 148 | |||
| 149 | =item get_element_by_id() | ||
| 150 | |||
| 151 | Type : Accessor | ||
| 152 | Title : get_element_by_id | ||
| 153 | Usage : $doc->get_element_by_id($id) | ||
| 154 | Function: Get element having id $id | ||
| 155 | Returns : Element object or undef if DNE | ||
| 156 | Args : id designator as string | ||
| 157 | |||
| 158 | =cut | ||
| 159 | |||
| 160 | sub get_element_by_id { | ||
| 161 | throw 'NotImplemented' => "Can't call 'get_element_by_id' on interface"; | ||
| 162 | } | ||
| 163 | |||
| 164 | =item get_elements_by_tagname() | ||
| 165 | |||
| 166 | Type : Accessor | ||
| 167 | Title : get_elements_by_tagname | ||
| 168 | Usage : $elt->get_elements_by_tagname($tagname) | ||
| 169 | Function: Get array of elements having given tag name | ||
| 170 | Returns : Array of elements or undef if no match | ||
| 171 | Args : tag name as string | ||
| 172 | |||
| 173 | =cut | ||
| 174 | |||
| 175 | sub get_elements_by_tagname { | ||
| 176 | throw 'NotImplemented' => | ||
| 177 | "Can't call 'get_elements_by_tagname' on interface"; | ||
| 178 | } | ||
| 179 | |||
| 180 | =back | ||
| 181 | |||
| 182 | =head2 Output methods | ||
| 183 | |||
| 184 | =over | ||
| 185 | |||
| 186 | =item to_xml() | ||
| 187 | |||
| 188 | Type : Serializer | ||
| 189 | Title : to_xml | ||
| 190 | Usage : $doc->to_xml | ||
| 191 | Function: Create XML string from document | ||
| 192 | Returns : XML string | ||
| 193 | Args : Formatting arguments as allowed by underlying package | ||
| 194 | |||
| 195 | =cut | ||
| 196 | |||
| 197 | sub to_xml { | ||
| 198 | throw 'NotImplemented' => "Can't call 'to_xml_string' on interface"; | ||
| 199 | } | ||
| 200 | |||
| 201 | =back | ||
| 202 | |||
| 203 | =head1 CITATION | ||
| 204 | |||
| 205 | If you use Bio::Phylo in published research, please cite it: | ||
| 206 | |||
| 207 | B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> | ||
| 208 | and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. | ||
| 209 | I<BMC Bioinformatics> B<12>:63. | ||
| 210 | L<http://dx.doi.org/10.1186/1471-2105-12-63> | ||
| 211 | |||
| 212 | =cut | ||
| 213 | |||
| 214 | 1; |