| 1 | package PurpleWiki::View::subtree; | ||
| 2 | use 5.005; | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Carp; | ||
| 6 | use PurpleWiki::View::Driver; | ||
| 7 | |||
| 8 | ############### Package Globals ############### | ||
| 9 | |||
| 10 | our $VERSION; | ||
| 11 | $VERSION = sprintf("%d", q$Id: subtree.pm 366 2004-05-19 19:22:17Z eekim $ =~ /\s(\d+)\s/); | ||
| 12 | |||
| 13 | our @ISA = qw(PurpleWiki::View::Driver); | ||
| 14 | |||
| 15 | |||
| 16 | ############### Overloaded Methods ############### | ||
| 17 | |||
| 18 | sub new { | ||
| 19 | my $proto = shift; | ||
| 20 | my $class = ref($proto) || $proto; | ||
| 21 | my $self = $class->SUPER::new(@_); | ||
| 22 | |||
| 23 | croak "No nid given to PurpleWiki::View::subtree->new()" | ||
| 24 | unless defined $self->{nid}; | ||
| 25 | |||
| 26 | # Object State | ||
| 27 | $self->{subtree} = undef; | ||
| 28 | |||
| 29 | bless($self, $class); | ||
| 30 | return $self; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub view { | ||
| 34 | my ($self, $wikiTree) = @_; | ||
| 35 | $self->{subtree} = undef; # Reset in case we're passed in a new tree | ||
| 36 | $self->SUPER::view($wikiTree); | ||
| 37 | return $self->{subtree}; | ||
| 38 | } | ||
| 39 | |||
| 40 | sub getSubTree { | ||
| 41 | my $self = shift; | ||
| 42 | return $self->{subtree}; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub recurse { | ||
| 46 | my $self = shift; | ||
| 47 | return if $self->{subtree}; # Bail fast if we found our NID. | ||
| 48 | $self->SUPER::recurse(@_); | ||
| 49 | } | ||
| 50 | |||
| 51 | sub traverse { | ||
| 52 | my $self = shift; | ||
| 53 | return if $self->{subtree}; # Bail fast if we found our NID. | ||
| 54 | $self->SUPER::traverse(@_); | ||
| 55 | } | ||
| 56 | |||
| 57 | sub Post { | ||
| 58 | my ($self, $nodeRef) = @_; | ||
| 59 | if ($nodeRef->isa('PurpleWiki::StructuralNode') and defined $nodeRef->id) { | ||
| 60 | if ($nodeRef->id eq $self->{nid}) { | ||
| 61 | $self->{subtree} = $nodeRef; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | } | ||
| 65 | 1; | ||
| 66 | __END__ |