| PurpleWiki documentation | Contained in the PurpleWiki distribution. |
PurpleWiki::View::subtree - Extracts a Subtree Rooted at a Given NID.
See get() in Transclusion.pm
Subtree extracts a subtree rooted at a node with a given NID. It's useful for doing transclusion or removing slices from a tree.
Returns a new PurpleWiki::View::subtree object.
nid is a PurpleWiki NID for the given node you're searching for. It is an error to not supply nid.
Returns a subtree of $tree with the root node of subtree being a node with the NID passed into new(). $tree is a PurpleWiki::Tree.
Returns the subtree found by the call view(). Returns undef if view() hasn't been called yet.
Matthew O'Connor, <matthew@canonical.org>
| PurpleWiki documentation | Contained in the PurpleWiki distribution. |
package PurpleWiki::View::subtree; use 5.005; use strict; use warnings; use Carp; use PurpleWiki::View::Driver; ############### Package Globals ############### our $VERSION; $VERSION = sprintf("%d", q$Id: subtree.pm 366 2004-05-19 19:22:17Z eekim $ =~ /\s(\d+)\s/); our @ISA = qw(PurpleWiki::View::Driver); ############### Overloaded Methods ############### sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = $class->SUPER::new(@_); croak "No nid given to PurpleWiki::View::subtree->new()" unless defined $self->{nid}; # Object State $self->{subtree} = undef; bless($self, $class); return $self; } sub view { my ($self, $wikiTree) = @_; $self->{subtree} = undef; # Reset in case we're passed in a new tree $self->SUPER::view($wikiTree); return $self->{subtree}; } sub getSubTree { my $self = shift; return $self->{subtree}; } sub recurse { my $self = shift; return if $self->{subtree}; # Bail fast if we found our NID. $self->SUPER::recurse(@_); } sub traverse { my $self = shift; return if $self->{subtree}; # Bail fast if we found our NID. $self->SUPER::traverse(@_); } sub Post { my ($self, $nodeRef) = @_; if ($nodeRef->isa('PurpleWiki::StructuralNode') and defined $nodeRef->id) { if ($nodeRef->id eq $self->{nid}) { $self->{subtree} = $nodeRef; } } } 1; __END__