Provided by: libcatmandu-perl_1.2020-1_all 

NAME
Catmandu::Path::simple - The default Catmandu path syntax
SYNOPSIS
my $data = {foo => {bar => ['first_bar', 'second_bar']}};
my $path = Catmandu::Path::simple->new("foo.bar.0");
my $getter = $path->getter;
my $first_bar = $getter->($data);
my $updater = $path->updater(sub { my $str = $_[0]; uc $str });
$updater->($data);
# => {foo => {bar => ['FIRST_BAR', 'second_bar']}}
# safer version with a type check
my $updater = $path->updater(if_string => sub { my $str = $_[0]; uc $str });
CONFIGURATION
path
The string version of the path. Required.
METHODS
getter
Returns a coderef that can get the values for the path. The coderef takes the data as argument and
returns the matching values as an arrayref.
my $path = Catmandu::Path::Simple->new(path => '$.foo');
my $data = {foo => 'foo', bar => 'bar'};
$path->getter->($data);
# => ['foo']
setter
Returns a coderef that can create the final part of the path and set it's value. In contrast to
"creator" this will only set the value if the intermediate path exists. The coderef takes the data as
argument and also returns the data.
my $path = Catmandu::Path::Simple->new(path => '$.foo.$append');
$path->creator(value => 'foo')->({});
# => {foo => ['foo']}
$path->creator(value => sub { my ($val, $data) = @_; $val // 'foo' })->({});
# => {foo => ['foo']}
# calling creator with no value creates a sub that takes the value as an
# extra argument
$path->creator->({}, 'foo');
$path->creator->({}, sub { my ($val, $data) = @_; $val // 'foo' });
# => {foo => ['foo']}
setter(\&callback|$value)
This is a shortcut for "setter(value =" \&callback|$value)>.
updater(value => \&callback)
Returns a coderef that can update the value of an existing path.
updater(if_* => [\&callback])
TODO
updater(if => [\&callback])
TODO
updater(if_* => \&callback)
TODO
updater(if => \&callback)
TODO
updater(\&callback)
This is a shortcut for "updater(value =" \&callback|$value)>.
creator(value => \&callback|$value)
Returns a coderef that can create the path and set it's value. In contrast to "setter" this also creates
the intermediate path if necessary. The coderef takes the data as argument and also returns the data.
my $path = Catmandu::Path::Simple->new(path => '$.foo.$append');
$path->creator(value => 'foo')->({});
# => {foo => ['foo']}
$path->creator(value => sub { my ($val, $data) = @_; $val // 'foo' })->({});
# => {foo => ['foo']}
# calling creator with no value creates a sub that takes the value as an
# extra argument
$path->creator->({}, 'foo');
$path->creator->({}, sub { my ($val, $data) = @_; $val // 'foo' });
# => {foo => ['foo']}
creator(\&callback|$value)
This is a shortcut for "creator(value =" \&callback|$value)>.
deleter
Returns a coderef that can delete the path. The coderef takes the data as argument and also returns the
data.
my $path = Catmandu::Path::Simple->new(path => '$.foo');
$path->deleter->({foo => 'foo', bar => 'bar'});
# => {bar => 'bar'}
SEE ALSO
Catmandu::Path.
perl v5.36.0 2023-03-03 Catmandu::Path::simple(3pm)