Skip to content

Commit 44593ee

Browse files
author
Chris White
committed
Cleanup; added --version and some perldoc [minor]
1 parent 6d92e7f commit 44593ee

File tree

12 files changed

+95
-25
lines changed

12 files changed

+95
-25
lines changed

lib/Object/TinyDefaults.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ my %defaults;
3535
sub import {
3636
my $class = shift;
3737
return unless $class eq __PACKAGE__;
38-
# Without this, it also gets imported into XML::Axk::V1 and
38+
# Without this, it also gets imported into XML::Axk::L1 and
3939
# axk_script_*, trashing symbols and preventing execution.
4040
my $pkg = caller;
4141
#print "Import into $pkg: (", join(', ', @_), ")\n";

lib/XML/Axk/App.pm

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,19 @@ my %CMDLINE_OPTS = (
4747
#INCLUDE => ['i','|include=s@'],
4848
#KEEP_GOING => ['k','|keep-going',false], #not in gawk
4949
#LIB => ['l','|load=s@'],
50-
#LINT => ['L','|lint:s'],
50+
LANGUAGE => ['L','|language:s'],
5151
# --man reserved
5252
# OUTPUT_FILENAME => ['o','|output=s', ""], # conflict with gawk
53+
# OPTIMIZE => ['O','|optimize'],
5354
#SANDBOX => ['S','|sandbox',false],
5455
#SOURCES reserved
5556
# --usage reserved
56-
PRINT_VERSION => ['V','|version', false],
57+
PRINT_VERSION => ['version','', false],
5758
DEFS => ['v','|var:s%'],
5859
# -? reserved
60+
#
61+
# gawk(1) long options: --dump-variables, --exec, --gen-po, --lint,
62+
# --profile
5963

6064
# Long-only options that are specific to axk.
6165
NO_INPUT => ['no-input'], # When set, don't read any files. This is so
@@ -131,6 +135,11 @@ sub Main {
131135
my %opts;
132136
parse_command_line(from => $lrArgs, into => \%opts);
133137

138+
if($opts{PRINT_VERSION}) {
139+
say "axk $VERSION";
140+
return 0;
141+
}
142+
134143
# Treat the first non-option arg as a script if appropriate
135144
unless(@{$opts{SOURCES}}) {
136145
croak "No scripts to run" unless @$lrArgs;
@@ -149,7 +158,7 @@ sub Main {
149158
} else {
150159
$core->load_script_text($text,
151160
"(cmd line script #@{[++$cmd_line_idx]})",
152-
true); # true => add a Vn if there isn't one in the script
161+
true); # true => add a Ln if there isn't one in the script
153162
}
154163
} #foreach source
155164

@@ -185,19 +194,59 @@ Version 0.1.0
185194
186195
axk [options] [--] [script] [input filename(s)]
187196
188-
=head1 OPTIONS
197+
=head1 INPUTS
189198
190199
A filename of C<-> represents standard input. To actually process a file
191200
named C<->, you will need to use shell redirection (e.g., C<< axk < - >>).
192201
Standard input is the default if no input filenames are given.
193202
194203
The first non-option argument is a program if no -e or -f are given.
195204
The script language version for a -e will default to the latest if the text
196-
on the command line doesn't match C</^\s*V\s*\d+[\s;]+/>.
205+
on the command line doesn't specify a language version.
206+
207+
=head1 OPTIONS
208+
209+
=over
210+
211+
=item -e, --source B<text>
212+
213+
Run the axk code given as B<text>.
214+
215+
=item -f, --file B<filename>
216+
217+
Run the axk code given in the file called B<filename>.
218+
219+
=item -L, --language B<language>
220+
221+
B<Not yet implemented:>
222+
Interpret the following B<-e> in axk language B<language>.
223+
224+
=item --show B<what>
225+
226+
Show debugging information. Currently implemented are:
227+
228+
=over
229+
230+
=item source
231+
232+
Show the Perl source generated from the provided axk code.
233+
234+
=back
235+
236+
=item -v, --var B<name>=B<value>
237+
238+
B<Not yet implemented:>
239+
Set B<name>=B<value>.
240+
241+
=item --version
242+
243+
Print the version of axk and exit
244+
245+
=back
197246
198247
=head1 AUTHOR
199248
200-
Christopher White, C<< <cxwembedded at gmail.com> >>
249+
Christopher White, C<cxwembedded at gmail.com>
201250
202251
=head1 BUGS
203252

lib/XML/Axk/Core.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ sub new {
392392
};
393393
my $self = bless($data, $class);
394394

395-
# Load this instance into the global namespace so the Vn packages can
395+
# Load this instance into the global namespace so the Ln packages can
396396
# get at it
397397
do {
398398
no strict 'refs';

run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
if [[ $# -eq 0 ]]; then
3-
args=(-f ex/xml1.axk t/ex1.xml)
3+
args=(-f t/ex/xml1.axk t/ex1.xml)
44
else
55
args=("$@")
66
fi

t/03-TODO.t

Lines changed: 0 additions & 14 deletions
This file was deleted.

t/03-additional.t

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!perl
2+
3+
use 5.018;
4+
use strict;
5+
use warnings;
6+
use Test::More;
7+
use Capture::Tiny 'capture_stdout';
8+
use XML::Axk::Core;
9+
10+
sub localpath {
11+
state $voldir = [File::Spec->splitpath(__FILE__)];
12+
return File::Spec->catpath($voldir->[0], $voldir->[1], shift)
13+
}
14+
15+
# Inline script, operation at runtime ============================= {{{1
16+
{
17+
my $core = XML::Axk::Core->new();
18+
$core->load_script_text(q{
19+
L1
20+
perform { say $E; } xpath("//item");
21+
perform { say $E; } xpath(q<//@attrname>);
22+
});
23+
# Note: q<> is because Perl tries to interpolate an array into "//@attrname"
24+
25+
my $out = capture_stdout { $core->run(localpath 'ex/ex1.xml'); };
26+
like($out, qr<(XML::DOM::Element[^\n]*\n){2}>, 'matched multiple elements');
27+
}
28+
29+
# }}}1
30+
31+
done_testing();
32+
__END__
33+
34+
35+
# vi: set ts=4 sts=4 sw=4 et ai fdm=marker fdl=1: #

ex/1.axk renamed to t/ex/1.axk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
say "hello from foo!";
2-
V1
2+
L1
33
#BEGIN { no strict 'refs'; say Dumper(\%{"axk_script_0::"}); };
44

55
pre_all {

ex/2.axk renamed to t/ex/2.axk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
V1
1+
L1
22
perform {
33
my $x = $C;
44
chomp $x;
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)