File: Node.pm

package info (click to toggle)
movabletype-opensource 5.1.4%2Bdfsg-4%2Bdeb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 32,996 kB
  • sloc: perl: 197,285; php: 62,405; sh: 166; xml: 117; makefile: 83; sql: 32
file content (58 lines) | stat: -rw-r--r-- 914 bytes parent folder | download
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
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__

=begin

=head1 NAME

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

=head1 AUTHOR & COPYRIGHT

Please see the XML::Elemental manpage for author, copyright, and
license information.

=cut

=end