NAME

Tree::Navigator::Node - a node to be displayed in a Tree::Navigator

SYNOPSIS

See Tree::Navigator

SPECIFICATION

Node structure

A node is an object that may contain

attributes

An attribute value is either undef or a Perl string. An attribute name is a non-empty Perl string. An attribute list is an ordered list of pairs (name, value).

content

A filehandle to some opaque content stored within the node.

children

A child is another node stored under the current node. A child name is a non-empty Perl string. The children of a node is an ordered list of pairs (name, child).

METHODS

Basic node access methods

attributes

my $attrs = $node->attributes;

Returns a hashref of key-value pairs. Values are either undef or Perl strings (or anything that may stringify to a Perl string).

children

my @children_names = $node->children;

Returns an ordered list of distinct, non-empty strings (the names of published children).

child

my $child = $node->child($child_name);

Returns a reference to the node stored under name $child_name within $node. The name $child_name does not necessarily belong to the list of published children (in which case this is a hidden child). If the node contains neither a published nor a hidden child under $child_name, an exception is raised.

$child_name must be a non-empty string and must not contain any slash ('/').

content

my $fh = $node->content or die "this node has no content";
while (my $content_line = <$fh>) {
  print $content_line;
}

Returns either undef, or a reference to an IO::Handle-like object having a getline method. Several successive calls to the content() method will return the same handle, but each time re-positioned at the beginning of the file (see IO::Seekable).

Derived access methods

descendent

my $descendent_node = $node->descendent($path);

Returns the descendent node path $path.

SUBCLASSING

To implement a new kind of node, you must subclass Tree::Navigator::Node and implement the methods described below.

MOUNT

_children

_child

_attributes

_content

is_parent

AUTHOR, BUGS, SUPPORT, COPYRIGHT

See Tree::Navigator.

TODO

- maybe this class should be split into a Role + a Base class

REST API
  /path/to/node
  /path/to/node?v=view_name
  /path/to/node/child_name
  /path/to/node.attributes
  /path/to/node.content
  /path/to/node.children
     ex: /path/to/file.doc
         /path/to/file.doc?v=frame
         /_toc/path/to/file.doc
         /path/to/file.doc?v=title
         /path/to/file.doc.attributes+content

   # OTHER POSSIBILITY
   /path/to/node.$view_name (handy for  .xml, .yaml, : auto MIME detection)
   /path/to/node;subitem.$view_name
   /path/to/node/@subitem.$view_name
   /path/to/node?search=query

   Q : diff between 
         /path/to/node/ : full data (attributes, children % content)
         /path/to/node 
?v=view
 p=part1,part2
 s=search_string



METHODS

  my $data = $node->data(@parts);
  my $view = $node->view($name, $view_args) || $tn->view()
  my $resp = $view->render($data, $node, $tn);

  $node->retrieve($parts) # subnodes, leaves, attributes, content
  $node->render($tn, $parts, $view, $view_args);
  my $view = $node->view($name, $view_args) || $tn->view()
  $node->present($tn, $parts, $view)
  $view->present($node)

Decide - $node->child($wrong_path) : should die or return undef ?

->mount(path       => 'foo',
        node_class => 'Filesys',
        mount_point => )