Catmandu::Path::simple(3pm) | User Contributed Perl Documentation | Catmandu::Path::simple(3pm) |
Catmandu::Path::simple - The default Catmandu path syntax
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 });
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']
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']}
This is a shortcut for "setter(value =" \&callback|$value)>.
Returns a coderef that can update the value of an existing path.
TODO
TODO
TODO
TODO
This is a shortcut for "updater(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']}
This is a shortcut for "creator(value =" \&callback|$value)>.
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'}
Catmandu::Path.
2023-03-03 | perl v5.36.0 |