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 => )
NAME
Tree::Navigator::Node - The great new Tree::Navigator::Node!
SYNOPSIS
...
SPECIFICATION
Node structure
A node is an object that may contain
An attribute value is either
undef
or a Perl string.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)
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.