10
10
# `axk_script_*` is used by only one Core instance.
11
11
12
12
package XML::Axk::L1 ;
13
- use XML::Axk::Base;
13
+ use XML::Axk::Base qw( :default now_names ) ;
14
14
15
15
use XML::Axk::Matcher::XPath;
16
16
use XML::Axk::Matcher::Always;
@@ -23,7 +23,7 @@ require XML::Axk::Language;
23
23
require Exporter;
24
24
our @EXPORT = qw(
25
25
pre_all pre_file post_file post_all perform
26
- always never xpath sel) ;
26
+ always never xpath sel on run ) ;
27
27
our @EXPORT_OK = qw( @SP_names ) ;
28
28
29
29
# Helpers ======================================================== {{{1
@@ -69,8 +69,8 @@ sub post_all :prototype(&) {
69
69
# # since that's how Perl's prototypes are set up the cleanest (block first).
70
70
# # @params required &action A block to execute when the pattern matches
71
71
# # @params required pattern The pattern
72
- sub perform :prototype(&@) {
73
- # say Dumper(\@_);
72
+ sub add_to_worklist {
73
+ # say "add_to_worklist args: ", Dumper(\@_);
74
74
my ($drAction , $refPattern , $when ) = @_ ;
75
75
# say "perform(): ", Dumper(\@_);
76
76
$when = $when // HI; # only on entry, by default
@@ -83,6 +83,28 @@ sub perform :prototype(&@) {
83
83
push @{$sandbox -> worklist}, [$refPattern , $drAction , $when ];
84
84
} # perform()
85
85
86
+ # User-facing alias for add_to_worklist
87
+ sub perform :prototype(&@) {
88
+ goto &add_to_worklist; # Need goto so that _sandbox() can use caller(1)
89
+ }
90
+
91
+ # run { action } [optional <when>] - syntactic sugar for sub {}, when
92
+ sub run :prototype(&;$) {
93
+ return @_ ;
94
+ } # run()
95
+
96
+ # pattern-first style - on {} run {} [when];
97
+ sub on :prototype(&@) {
98
+ my ($drMakeMatcher , $drAction , $when ) = @_ ;
99
+
100
+ # say "MakeMatcher: ", Dumper($drMakeMatcher);
101
+ my $matcher = &$drMakeMatcher ;
102
+ # say "Matcher: ", Dumper($matcher);
103
+
104
+ @_ =($drAction , $matcher , $when );
105
+ goto &add_to_worklist;
106
+ } # on()
107
+
86
108
# }}}1
87
109
# Definers for matchers ========================================== {{{1
88
110
@@ -101,7 +123,7 @@ sub never :prototype() {
101
123
} # never()
102
124
103
125
# Make an XPath matcher
104
- sub xpath :prototype(@) {
126
+ sub xpath {
105
127
my $path = shift or croak(" No expression provided!" );
106
128
$path = $$path if ref $path ;
107
129
@@ -114,7 +136,7 @@ sub xpath :prototype(@) {
114
136
} # xpath()
115
137
116
138
# Make a selector matcher
117
- sub sel :prototype(@) {
139
+ sub sel {
118
140
my $path = shift or croak(" No expression provided!" );
119
141
$path = $$path if ref $path ;
120
142
@@ -132,7 +154,7 @@ sub sel :prototype(@) {
132
154
# Script parameters ============================================== {{{1
133
155
134
156
# Script-parameter names
135
- our @SP_names = qw( $C @F $D $E) ;
157
+ our @SP_names = qw( $C @F $D $E $NOW ) ;
136
158
137
159
sub update {
138
160
# say "L1::update: ", Dumper(\@_);
@@ -141,6 +163,8 @@ sub update {
141
163
142
164
$hrSP -> {' $D' } = $opts {document } or croak(" No document" );
143
165
$hrSP -> {' $E' } = $opts {record } or croak(" No record" );
166
+ croak(" You are in a timeless maze" ) unless defined $opts {NOW };
167
+ $hrSP -> {' $NOW' } = now_names $opts {NOW };
144
168
# while (my ($key, $value) = each %new_sps) { }
145
169
} # update()
146
170
0 commit comments