|
| 1 | +# NAME |
| 2 | + |
| 3 | +XML::Axk::Core::L1 - ack-like XML processor, language 1 |
| 4 | + |
| 5 | +# EXAMPLE |
| 6 | + |
| 7 | + L1 |
| 8 | + on { xpath(q<//item>) } run {say "$NOW: " . $E->getTagName}, CIAO |
| 9 | + # "CIAO" can also be "HI" or "BYE" (default HI). |
| 10 | + # "entering" is a synonym for "on" with no HI/BYE/CIAO. |
| 11 | + whenever { xpath(q<//item>) } run {say "$NOW: " . $E->getTagName}; |
| 12 | + # the same as the "on ... CIAO" line |
| 13 | + leaving { xpath(q<//item>) } run {say "$NOW: " . $E->getTagName}; |
| 14 | + |
| 15 | +# PATTERNS AND ACTIONS |
| 16 | + |
| 17 | +## `on {<matcher>} run {<action>} [, <when>]` |
| 18 | + |
| 19 | +Whenever `<matcher>` says that a node matches, run `<action>`. |
| 20 | +The optional `<when>` parameter says when in the course of processing to |
| 21 | +run `<action>`: |
| 22 | + |
| 23 | +- `HI` |
| 24 | + |
| 25 | + When the node is first reached, before any of its children are processed |
| 26 | + |
| 27 | +- `BYE` |
| 28 | + |
| 29 | + After all of the node's children have been processed. |
| 30 | + |
| 31 | +- `CIAO` |
| 32 | + |
| 33 | + Both `HI` and `BYE`. Suggestions for alternative terminology are welcome. |
| 34 | + |
| 35 | +## `entering`, `whenever` `leaving` |
| 36 | + |
| 37 | + entering {<matcher>} run {<action>} |
| 38 | + whenever {<matcher>} run {<action>} |
| 39 | + leaving {<matcher>} run {<action>} |
| 40 | + |
| 41 | +The same as `on {} run {}`, with `when` set to `HI`, `CIAO`, or `BYE` |
| 42 | +respectively. |
| 43 | + |
| 44 | +## `perform { <action> } <matcher> [, <when>]` |
| 45 | + |
| 46 | +If you prefer RPN, or you want to save some characters, you can put the |
| 47 | +`<matcher>` after the `<action>` using `perform`. For example, |
| 48 | +the following two lines have exactly the same effect: |
| 49 | + |
| 50 | + on { xpath(q<//item>) } run {say "$NOW: " . $E->getTagName}, CIAO |
| 51 | + perform {say "$NOW: " . $E->getTagName} xpath(q<//item>), CIAO |
| 52 | + |
| 53 | +# VARIABLES |
| 54 | + |
| 55 | +When an `<action>` is running, it has access to predefined variables |
| 56 | +that hold the state of the element being matched. This is similar to `$0`, |
| 57 | +`$1`, ... in awk. |
| 58 | + |
| 59 | +- **$D** |
| 60 | + |
| 61 | + The current XML document |
| 62 | + |
| 63 | +- **$E** |
| 64 | + |
| 65 | + The XML element that was matched |
| 66 | + |
| 67 | +- **$NOW** |
| 68 | + |
| 69 | + The current phase, as a human-readable string: `entering` for `HI`, |
| 70 | + `leaving` for `BYE`, and `BOTH` for `CIAO`. |
| 71 | + |
| 72 | +# MATCHERS |
| 73 | + |
| 74 | +## `xpath('xpath expression')` |
| 75 | + |
| 76 | +Match nodes that match the given XPath expression. Remember that Perl will |
| 77 | +interpolate `@name` in double-quotes, so single-quote or `q{}` your XPath |
| 78 | +expressions. |
| 79 | + |
| 80 | +## `sel('selector')` |
| 81 | + |
| 82 | +Match nodes that match the given selector. |
| 83 | + |
| 84 | +## `always`, `never` |
| 85 | + |
| 86 | +Always or never match, respectively. |
| 87 | + |
| 88 | +# SPECIAL ACTIONS |
| 89 | + |
| 90 | +## `pre_all {<block>}` |
| 91 | + |
| 92 | +Run `<block>` before any file is processed. |
| 93 | + |
| 94 | +## `pre_file {<block>}` |
| 95 | + |
| 96 | +Run `<block>($filename)` before each file is processed. |
| 97 | + |
| 98 | +## `post_file {<block>}` |
| 99 | + |
| 100 | +Run `<block>($filename)` after each file is processed. |
| 101 | + |
| 102 | +## `post_all {<block>}` |
| 103 | + |
| 104 | +Run `<block>` after all files have been processed. |
| 105 | + |
| 106 | +# AUTHOR |
| 107 | + |
| 108 | +Christopher White, `cxwembedded at gmail.com` |
| 109 | + |
| 110 | +# CONTACT |
| 111 | + |
| 112 | +For any bug reports, feature requests, or questions, please see the |
| 113 | +information in [XML::Axk](https://metacpan.org/pod/XML::Axk). |
| 114 | + |
| 115 | +# LICENSE AND COPYRIGHT |
| 116 | + |
| 117 | +Copyright (c) 2018 Christopher White. All rights reserved. |
| 118 | + |
| 119 | +This program is free software; you can redistribute it and/or modify it |
| 120 | +under the terms of the the Artistic License (2.0). Details are in the LICENSE |
| 121 | +file accompanying this distribution. |
0 commit comments