++ed by:
David F. Houghton

NAME

TPath::Attributes::Standard - the standard collection of attributes available to any forester by default

VERSION

version 1.006

DESCRIPTION

TPath::Attributes::Standard provides the attributes available to all foresters. TPath::Attributes::Standard is a role which is composed into TPath::Forester.

METHODS

@true

Returns a value, 1, evaluating to true.

@false

Returns a value, undef, evaluating to false.

@this

Returns the node itself.

@uid

Returns a string representing the unique path in the tree leading to this node. This consists of the index of the node among its parent's children concatenated to the uid of its parent with / as a separator. The uid of the root node is always /. That of its second child is /1. That of the first child of this child is /1/0. And so on.

@echo(//a)

Returns its parameter.

@leaf

Returns whether the node is without children.

@pick(//foo,1)

Takes a collection and an index and returns the indexed member of the collection.

@size(//foo)

Takes a collection and returns its size.

@size

Returns the size of the tree rooted at the context node.

@width

Returns the number of leave under the context node.

@depth

Returns the number of ancestors of the context node.

@height

Returns the greatest number of generations, inclusive, separating this node from a leaf. Leaf nodes have a height of 1, their parents, 2, etc.

@root

Returns whether the context node is the tree root.

@null

Returns undef. This is chiefly useful as an argument to other attributes. It will always evaluate as false if used as a predicate.

@index

Returns the index of this node among its parent's children, or -1 if it is the root node.

@log('m1','m2','m3','...')

Prints each message argument to the log stream, one per line, and returns 1. See attribute log_stream in TPath::Forester.

@id

Returns the id of the current node, if any.

@card(//a)

Returns the cardinality of its parameter. If its parameter evaluates to a list reference, it is the number of items in the list. If it evaluates to a hash reference, it is the number of mappings. The usual parameters are expressions or attributes. Anything which evaluates to undef will have a cardinality of 0. Anything which does not evaluate to a collection reference will have a cardinality of 1.

  //foo[@card(bar) = @card(@quux)]

@at(foo//bar, 'baz', 1, 2, 3)

Returns the value of the named attribute with the given parameters at the first TPath::Context selected by the path parameter evaluated relative to the context node. In the case of

  @at(foo//bar, 'baz', 1, 2, 3)

The path parameter is foo//bar, the relevant attribute is @baz, and it will be evaluated using the parameters 1, 2, and 3. Other examples:

  @at(leaf::*[1], 'id')   # the id of the second leaf under this node
  @at(*/*, 'height')      # the height of the first grandchild of this node
  @at(/>foo, 'depth')     # the depth of the closest foo node

It is the first TPath::Context selected by the path whose attribute is evaluated, that is, the first node returned, so it is relevant that paths are evaluated left-to-right, depth-first, and post-ordered, descendants being returned before their ancestors.

@all(@a, b, 1, "foo")

True if all its parameters evaluate to true, the standard boolean interpretation being given to collection parameters.

@none(@a, b, 1, "foo")

True if all its parameters evaluate to false, the standard boolean interpretation being given to collection parameters.

@some(@a, b, 1, "foo")

True if any of its parameters evaluates to true, the standard boolean interpretation being given to collection parameters.

@one(@a, b, 1, "foo")

True if only one of its parameters evaluates to true, the standard boolean interpretation being given to collection parameters.

@tcount(@a, b, 1, "foo")

Returns the number of parameters evaluating to true.

@fcount(@a, b, 1, "foo")

Returns the number of parameters evaluating to false.

@var(@a, "key") =method @v(@a, "key", "value")

Returns the value of the given variable in the context, also setting it if the optional values parameters are supplied. This attribute is accessible as either @var or @v

  my $e = $f->path('/*[@v("size", @tsize)]');
  $e->select($some_tree);
  say $e->vars->{size};   # prints the number of nodes in the tree

If a single parameter is passed in as the value, this value is stored under the key. If more than one parameter is passed in, a reference to the values array is stored.

@clear_var("key")

Deletes the given value from the expression's variable hash, returning any value deleted.

REQUIRED METHODS

_kids

See TPath::Forester

children

See TPath::Forester

parent

See TPath::Forester

AUTHOR

David F. Houghton <dfhoughton@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by David F. Houghton.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.




Hosting generously
sponsored by Bytemark