Skip to content

Commit ecea601

Browse files
author
Chris White
committed
Updated documentation
1 parent 2ed36dc commit ecea601

File tree

3 files changed

+137
-15
lines changed

3 files changed

+137
-15
lines changed

L1.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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.

MANIFEST.SKIP

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# MANIFEST.SKIP for Text::PerlPP
22

3+
# Markdown files that we keep for GitHub, but don't need on CPAN
4+
^L1.md
5+
36
# Avoid version control files.
47
\bRCS\b
58
\bCVS\b

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,26 @@ To install this module, run the following commands:
1313

1414
After installation, run `axk`. Options are similar to `awk`. Input scripts
1515
are Perl 5.18 with functions to, e.g., run on any node matching a given XPath.
16+
See [L1.md](L1.md) for more details. For example, the script
1617

17-
## SUPPORT AND DOCUMENTATION
18-
19-
After installing, you can find documentation for this module with the
20-
perldoc command.
18+
L1
19+
on { xpath(q<//item>) } run { say "$NOW: " . $E->getTagName };
2120

22-
perldoc XML::Axk
21+
or the equivalent command line
2322

24-
You can also look for information at:
23+
axk -e 'on { xpath(q<//item>) } run { say "$NOW: " . $E->getTagName }' t/ex/ex1.xml
2524

26-
RT, CPAN's request tracker (report bugs here)
27-
http://rt.cpan.org/NoAuth/Bugs.html?Dist=XML-Axk
25+
will print the tag name of each `//item` node in the input, along with an
26+
indication (`$NOW`) of whether the action is being run when `entering` or
27+
`leaving` the node.
2828

29-
AnnoCPAN, Annotated CPAN documentation
30-
http://annocpan.org/dist/XML-Axk
31-
32-
CPAN Ratings
33-
http://cpanratings.perl.org/d/XML-Axk
29+
## SUPPORT AND DOCUMENTATION
3430

35-
Search CPAN
36-
http://search.cpan.org/dist/XML-Axk/
31+
After installing, you can find documentation for this module with the
32+
perldoc command:
3733

34+
- `perldoc XML::Axk::App` for command-line usage instructions
35+
- `perldoc XML::Axk::L1` for the language reference
3836

3937
## LICENSE AND COPYRIGHT
4038

0 commit comments

Comments
 (0)