1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
package XML::Elemental::Document;
use strict;
use base qw( XML::Elemental::Node );
use Scalar::Util qw(weaken);
sub root_element { $_[0]->{contents} }
sub contents {
if (@_ > 1) {
$_[0]->{contents} = ref $_[1] eq 'ARRAY' ? $_[1]->[0] : $_[1];
weaken($_[0]->{contents}->{parent} = $_[0]);
}
return $_[0]->{contents} ? [$_[0]->{contents}] : [];
}
sub attributes { } # deprecated. documents never have attributes.
sub DESTROY {
$_[0]->{contents}->DESTROY if $_[0]->{contents};
} # starts circular reference teardown
1;
__END__
=begin
=head1 NAME
XML::Elemental::Document - a generic document object.
=head1 DESCRIPTION
XML::Elemental::Document is a subclass of L<XML::Elemental::Node>
that can be used with the Elemental parser to represent the document
(root) node.
=head1 METHODS
=item XML::Elemental::Document->new
Parameterless constructor. Returns an instance of the object.
=item $doc->contents([\@children])
Returns an ordered array reference of direct sibling
objects. In the case of the document object it will return 0
to 1 elements. Returns a reference to an empty array if the
element does not have any siblings. If a parameter is passed
all the direct siblings are (re)set.
=item $doc->root_element;
Returns the root element of the document. This a connivence method that
is the equivalent of:
$doc->contents->[0];
=item $doc->root
Inherited from L<XML::Elemental::Node>, returns a reference to itself.
=item $doc->ancestors
Inherited from L<XML::Elemental::Node>, returns undef. The
document object never has ancestors.
=item $doc->in($element)
Inherited from L<XML::Elemental::Node>, returns undef. The
document object is always the root of the tree.
=head1 AUTHOR & COPYRIGHT
Please see the XML::Elemental manpage for author, copyright, and
license information.
=cut
=end
|