1Data::Grove::Visitor(3)User Contributed Perl DocumentatioDnata::Grove::Visitor(3)
2
3
4

NAME

6       Data::Grove::Visitor - add visitor/callback methods to Data::Grove
7       objects
8

SYNOPSIS

10        use Data::Grove::Visitor;
11
12        @results = $object->accept ($visitor, ...);
13        @results = $object->accept_name ($visitor, ...);
14        @results = $object->children_accept ($visitor, ...);
15        @results = $object->children_accept_name ($visitor, ...);
16

DESCRIPTION

18       Data::Grove::Visitor adds visitor methods (callbacks) to Data::Grove
19       objects.  A ``visitor'' is a class (a package) you write that has
20       methods (subs) corresponding to the objects in the classes being
21       visited.  You use the visitor methods by creating an instance of your
22       visitor class, and then calling `"accept($my_visitor)"' on the top-most
23       object you want to visit, that object will in turn call your visitor
24       back with `"visit_OBJECT"', where OBJECT is the type of object.
25
26       There are several forms of `"accept"'.  Simply calling `"accept"' calls
27       your package back using the object type of the object you are visiting.
28       Calling `"accept_name"' on an element object calls you back with
29       `"visit_name_NAME"' where NAME is the tag name of the element, on all
30       other objects it's as if you called `"accept"'.
31
32       All of the forms of `"accept"' return a concatenated list of the result
33       of all `"visit"' methods.
34
35       `"children_accept"' calls `"accept"' on each of the children of the
36       element.  This is generally used in element callbacks to recurse down
37       into the element's children, you don't need to get the element's
38       contents and call `"accept"' on each item.  `"children_accept_name"'
39       does the same but calling `"accept_name"' on each of the children.
40       `"attr_accept"' calls `"accept"' on each of the objects in the named
41       attribute.
42
43       Refer to the documentation of the classes you are visiting (XML::Grove,
44       etc.) for the type names (`"element"', `"document"', etc.) of the
45       objects it implements.
46

RESERVED NAMES

48       The hash keys `"Contents"' and `"Name"' are used to indicate objects
49       with children (for `"children_accept"') and named objects (for
50       `"accept_name"').
51

NOTES

53       These are random ideas that haven't been implemented yet:
54
55       ยท   Several objects fall into subclasses, or you may want to be able to
56           subclass a visited object and still be able to tell the difference.
57           In SGML::Grove I had used the package name in the callback
58           (`"visit_SGML_Element"') instead of a generic name
59           (`"visit_element"').  The idea here would be to try calling
60           `"visit_PACKAGE"' with the most specific class first, then try
61           superclasses, and lastly to try the generic.
62

AUTHOR

64       Ken MacLeod, ken@bitsko.slc.ut.us
65

SEE ALSO

67       perl(1), Data::Grove
68
69       Extensible Markup Language (XML) <http://www.w3c.org/XML>
70
71
72
73perl v5.30.0                      2019-07-26           Data::Grove::Visitor(3)
Impressum