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