Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: renormalist/app-dpath
base: 7df119b986
...
head fork: renormalist/app-dpath
compare: 183db0f191
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
16 lib/App/DPath/Command/search.pm
@@ -15,7 +15,7 @@ sub opt_spec {
[ "outtype|o=s", "output format, [yaml(default), json, dumper, xml]" ],
[ "separator|s=s", "sub entry separator for output format 'flat' (default=;)" ],
[ "fb", "on output format 'flat' use [brackets] around outer arrays" ],
- [ "fi", "on output format 'flat' prefix outer arrays with index" ],
+ [ "fi", "on output format 'flat' prefix outer array lines with index" ],
);
}
@@ -110,13 +110,21 @@ sub _format_flat_inner_scalar {
sub _format_flat_inner_array {
my ($self, $opt, $result) = @_;
- return join($opt->{separator}, map { "".$_ } @$result);
+ return join($opt->{separator}, map {
+ # only SCALARS allowed (where reftype returns undef)
+ die "Unsupported innermost nesting (".reftype($_).")\n" if defined reftype($_);
+ "".$_
+ } @$result);
}
sub _format_flat_inner_hash {
my ($self, $opt, $result) = @_;
- return join($opt->{separator}, map { "$_=".$result->{$_} } keys %$result);
+ return join($opt->{separator}, map { my $v = $result->{$_};
+ # only SCALARS allowed (where reftype returns undef)
+ die "Unsupported innermost nesting (".reftype($v).")\n" if defined reftype($v);
+ "$_=".$v
+ } keys %$result);
}
sub _format_flat_outer {
@@ -262,5 +270,3 @@ Writes out the result set according to format.
=head2 validate_args
=cut
-
-# echo "" ; for p in '//firstname' '//metadata' '//metadata//Affe' '//reports' ; do echo $p ; perl -Ilib script/dpath -o flat $p < t/flatabledata.yaml ; echo "" ; done
View
18 t/app_dpath.t
@@ -78,4 +78,22 @@ check (qw(cfggeneral yaml), '//home', [ "/usr/home/max" ]);
check (qw(cfggeneral yaml), '//mono//bl', [ 2 ]);
check (qw(cfggeneral yaml), '//log', [ "/usr/log/logfile" ]);
+diag 'Ignore output warnings about "Unsupported innermost nesting"...';
+
+my $program;
+my $infile;
+my $path;
+my $ret;
+
+$program = "$^X -Ilib script/dpath";
+$infile = "t/flatabledata.yaml";
+
+$path = "//UnsupportedInnermostHash";
+$ret = system("$program -o flat '$path' $infile");
+isnt ($ret, 0, "deny unsupported innermost HASH");
+
+$path = "//UnsupportedInnermostArray";
+$ret = system("$program -o flat '$path' $infile");
+isnt ($ret, 0, "deny unsupported innermost ARRAY");
+
done_testing;
View
14 t/flatabledata.yaml
@@ -7,8 +7,9 @@ names:
- firstname: Birne
lastname: Dingens
metadata:
+ Eric: The flat one from the 90s
Affe:
- size: big
+ size: average
coolness: big
Zomtec:
size: average
@@ -37,3 +38,14 @@ reports:
Zomtec: slow talking speed
Birne: unexpected in many respects
- "single report string"
+
+UnsupportedInnermostHash:
+ Nesting:
+ Level:
+ foo: 111
+ bar: 222
+UnsupportedInnermostArray:
+ Nesting:
+ Level:
+ - foo
+ - bar

No commit comments for this range

Something went wrong with that request. Please try again.