XML::Elemental::Node - base class for all other XML::Elemental objects.


XML-Elemental documentation Contained in the XML-Elemental distribution.

Index


Code Index:


XML-Elemental documentation Contained in the XML-Elemental distribution.

package XML::Elemental::Node;
use strict;

sub new { bless {}, $_[0]; }

sub root {
    my $e = shift;
    while ($e->{parent}) { $e = $e->{parent} }
    return $e;
}

sub ancestors {
    my $e = shift;
    my @a;
    while ($e->{parent}) {
        $e = $e->{parent};
        push @a, $e;
    }
    return @a;
}

sub in_element {
    my ($e, $a) = @_;
    while ($e->{parent}) {
        $e = $e->{parent};
        return 1 if $e == $a;
    }
    return 0;
}

sub DESTROY {
    my $self = shift;
    if ($self->{contents}) {
        for (@{$self->{contents}}) {
            $_->DESTROY if $_ && $_->isa('XML::Elemental::Node');
        }
    }
    %$self = ();    # safety first.
}

1;

__END__