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 (pratique pour .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 => )
Tree::Navigator::Node - The great new Tree::Navigator::Node!
...
A node is an object that may contain
An attribute value is either undef or a Perl string.
undef
An attribute name is a non-empty Perl string.
For a given node, the list of published attributes is an ordered list of distinct attribute names (possibly empty).
An attribute is a scalar value (possibily undefined) stored under an attribute name. Some attributes may be hidden, i.e. not published in the list of attribute names, but nevertheless
The list of children names is an ordered list of distinct, non-empty scalar values.
A child is a node stored under a child name.
a collection of scalar values pairs (name, value)
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).
my @children_names = $node->children;
Returns an ordered list of distinct, non-empty strings (the names of published children).
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
$node
$child_name must be a non-empty string and must not contain any slash ('/').
'/'
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).
getline
content()
my $descendent_node = $node->descendent($path);
Returns the descendent node path $path.
$path
To implement a new kind of node, you must subclass Tree::Navigator::Node and implement the methods described below.
Tree::Navigator::Node
See Tree::Navigator.
To install Tree::Navigator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tree::Navigator
CPAN shell
perl -MCPAN -e shell install Tree::Navigator
For more information on module installation, please visit the detailed CPAN module installation guide.