XML::Grove::Sub(3pm)

XML::Grove::Sub3pm

Run a filter sub over a grove

Usage

 use XML::Grove::Sub;
 # Using filter method on XML::Grove::Document or XML::Grove::Element:
 @results = $grove_object->filter(\&sub [, ...]);
 # Using an XML::Grove::Sub instance:
 $filterer = XML::Grove::Sub->new();
 @results = $grove_object->accept($filterer, \&sub [, ...]);

Overview

"XML::Grove::Sub" executes a sub, the filter, over all objects in a grove and returns a list of all the return values from the sub. The sub is called with the grove object as it's first parameter and passing the rest of the arguments to the call to `"filter()"' or `"accept()"'.

Examples

The following filter will return a list of all `"foo"' or `"bar"' elements with an attribute `"widget-no"' beginning with `"A"' or `"B"'.

  @results = $grove_obj->filter(sub {
      my $obj = shift;
      if ($obj->isa('XML::Grove::Element')
          && (($obj->{Name} eq 'foo')
              || ($obj->{Name} eq 'bar'))
          && ($obj->{Attributes}{'widget-no'} =~ /^[AB]/)) {
          return ($obj);
      }
      return ();
  });

Releases

13 releases since Debian 2.2 (Potato); the text changed 6 times.

  1. 2.2
  2. 3.0
  3. 3.1–5.0
  4. 6.0–9
  5. 10
  6. 11
  7. 12–13

Author

Ken MacLeod, [email protected]

From libxml-grove-perl 0.46alpha-14 in Debian 13 (Trixie). Parsed by carta from the page's man source.