PurpleWiki::StructuralNode - Structural node object


PurpleWiki documentation  | view source Contained in the PurpleWiki distribution.

Index


NAME

Top

PurpleWiki::StructuralNode - Structural node object

SYNOPSIS

Top

  use PurpleWiki::InlineNode;
  use PurpleWiki::StructuralNode;

  # Create a 'section' node
  my $node = PurpleWiki::StructuralNode->new(type=>'section');

  # Insert a child node, and assign it to $currentNode
  my $currentNode = $node->insertChild;

  # Set current node's type to 'h'
  $currentNode->type('h');

  # Set node content to a new inline node of type 'text' and of
  # content 'Hello, world!'
  $currentNode->content(
      [PurpleWiki::InlineNode->new(type=>'text',
                                   content=>'Hello, world!')] );

  # The resulting tree is:
  # 
  # SECTION
  #    |
  #    +--- H: [TEXT: Hello, world!]
  #
  # where "[TEXT: Hello, world!]" refers to an inline node of type
  # 'text' and content 'Hello, world!'.

DESCRIPTION

Top

Structural nodes are the main structural component of PurpleWiki trees, representing document constructs such as sections, paragraphs, and list items. The basic data structure is:

  PurpleWiki::StructuralNode = {
    type     => document|section|h|p|pre|indent|ul|ol|li|dl|dt|dd
    id       => int
    content  => [PurpleWiki::InlineNode, ...]
    parent   => PurpleWiki::StructuralNode
    children => [PurpleWiki::StructuralNode, ...]
  }

The document, section, indent, ul, ol, and dl nodes types are structural-only; their content field will always be undefined. Only the root node of a tree should be of type document. The content field is a reference to a list of inline nodes, and represents the content of the structural node.

BNF CONSTRAINTS

Top

PurpleWiki does not currently enforce constraints for structural node types. For example, you can create a section node with content, or a p node with children, even though neither of those are technically legal.

The BNF constraints for structural nodes are:

  document ::= section
  section ::= h|p|indent|ul|ol|dl|pre
  indent ::= p|indent
  ul ::= li|ul|ol|dl
  ol ::= li|ol|ul|dl
  dl ::= dt dd|dl|ul|ol

METHODS

Top

new(%options)

Constructor. Blesses hash with fields type, id, and content. Values for these fields may be passed as parameters via %options.

insertChild(%options)

Creates a new structural node and pushes it onto the current node's list of children. Returns the value of the new child node. You can set the child node's fields via the %options parameter, which will be passed onto the constructor.

parent()

Returns the parent node.

children()

Returns the reference to the list of children.

Accessors/Mutators

 type()
 id()
 content()

AUTHORS

Top

Chris Dent, <cdent@blueoxen.org>

Eugene Eric Kim, <eekim@blueoxen.org>

SEE ALSO

Top

PurpleWiki::Tree, PurpleWiki::InlineNode.


PurpleWiki documentation  | view source Contained in the PurpleWiki distribution.