| WSST documentation | Contained in the WSST distribution. |
WSST::Schema::Node - Schema::Node class of WSST
This is a base class for tree structure of schema.
Constructor.
Accessor for the name.
Accessor for the title.
Accessor for the desc.
Accessor for the examples.
Accessor for the type.
Accessor for the children.
Accessor for the multiple.
Accessor for the nullable.
Returns Node objects of path.
Returns names of path
Returns arrayref which contains all child nodes.
http://code.google.com/p/wsst/
Mitsuhisa Oshikawa <mitsuhisa [at] gmail.com> Yusuke Kawasaki <u-suke [at] kawa.net>
Copyright 2008 WSS Project Team
| WSST documentation | Contained in the WSST distribution. |
package WSST::Schema::Node; use strict; use base qw(WSST::Schema::Base); __PACKAGE__->mk_accessors(qw(name title desc examples type children multiple nullable)); __PACKAGE__->mk_ro_accessors(qw(parent depth)); use constant BOOL_FIELDS => qw(multiple nullable); our $VERSION = '0.1.1'; sub new { my $class = shift; my $self = $class->SUPER::new(@_); $self->{depth} = ($self->parent ? $self->parent->depth + 1 : 1); if ($self->{children}) { foreach my $node (@{$self->{children}}) { $node->{parent} = $self; $node = $class->new($node); } } return $self; } sub path { my $self = shift; my $min = shift || 0; my $path = []; for (my $p = $self; $p && $p->depth >= $min; $p = $p->parent) { unshift(@$path, $p); } return $path; } sub path_names { my $self = shift; my $min = shift || 0; return [map {$_->name} @{$self->path($min)}]; } sub to_array { my $self = shift; my $array = [$self]; my $stack = [[$self, 0]]; while (my $val = pop(@$stack)) { my ($node, $i) = @$val; for (; $i < @{$node->{children}}; $i++) { my $child = $node->{children}->[$i]; push(@$array, $child); if ($child->{children}) { push(@$stack, [$node, $i+1]); push(@$stack, [$child, 0]); last; } } } return $array; }
1;