NAME

App::DPath - Cmdline tool around Data::DPath

SYNOPSIS

use App::DPath;

my $path = '//some/dpath';
my $data = App::DPath::read_in ($file);
my @resultlist = dpath($path)->match($data);
my $output = App::DPath::write_out ({}, \@resultlist);
print $output;

DESCRIPTION

This module handles the input and output for the dpath command.

SUBROUTINES

read_in

my $data = App::DPath::read_in ($file, $intype, $yamlmod);

read_in takes a filename as its mandatory argument. It reads the data from the file according to the type specified in the second argument (which defaults to 'yaml') and returns the resulting data structure. Other data types are: 'json', 'xml', 'ini', 'cfggeneral', 'dumper' and 'tap'.

The optional third argument specifies a list of modules to use to parse YAML. The first available module in the list is used. If unspecified it defaults to YAML::XS, YAML::Old, YAML and YAML::Tiny.

write_out

my $formatted_out = App::DPath::write_out ($opt, $resultlist);

write_out returns the results as a string formatted according to the options in the $opt hashref. Those options are

outtype

One of

yaml (the default)
json
xml
ini
dumper
flat
separator

For outtype=flat only. This option sets the field separator for the output.

fb

For outtype=flat only. Display outer arrays inside square brackets.

fi

For outtype=flat only. Prefix outer array lines with index.

yaml-module

For outtype=yaml only. The YAML processing module to use. If not provided it uses the same default as read_in.

$resultstring is expected to be an arrayref, usually the result of running a match against the read-in data.

SEE ALSO

dpath is the command-line wrapper around this module. Its documentation includes details of the "flat" output format along with some usage examples.

Data::DPath is the underlying path engine.

AUTHOR

Steffen Schwigon <ss5@renormalist.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2019 by Steffen Schwigon.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.