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 });
The string version of the path. Required.
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.
creator
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)>.
setter(value =
Returns a coderef that can update the value of an existing path.
TODO
This is a shortcut for updater(value = \&callback|$value)>.
updater(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.
setter
This is a shortcut for creator(value = \&callback|$value)>.
creator(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.
To install Catmandu, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catmandu
CPAN shell
perl -MCPAN -e shell install Catmandu
For more information on module installation, please visit the detailed CPAN module installation guide.