Catman...simple(3pm)
β¨ NAME β¨
okay so bestie, meet Catmandu::Path::simple β it's the default Catmandu path syntax, no cap π
this page comes to you straight out of the User Contributed Perl Documentation (that's the manual name, mwah) and it lives in section 3pm, the perl module corner of the world πΈ
π¦ SYNOPSIS π¦
here's the vibe, literally copied for u:
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 });
see how it just works? obsessed π
π CONFIGURATION π
pathβ the string version of the path. Required, so don't ghost it fr fr π
π METHODS π
πΈ getter
hands u back a coderef that can get the values for the path. the coderef takes the data as its argument and returns the matching values as an arrayref. it's giving little retriever energy π«Ά
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. and like, in contrast to "creator", this one will only set the value if the intermediate path exists β it does not build the road, it just drives on it πβ¨ 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']}
(yes bestie, that's the example exactly as the page serves it β we do not edit the source material in this house π )
π setter(&callback|$value)
this is a shortcut for "setter(value =" \&callback|$value)>. tiny, iconic, efficient π
π updater(value => &callback)
returns a coderef that can update the value of an existing path. if the path isn't there... well, it's not there, ok? π
β updater(if_* => [&callback])
TODO π (the page really just says TODO, and we respect the TODO)
β updater(if => [&callback])
TODO π
β updater(if_* => &callback)
TODO π
β updater(if => &callback)
TODO π
π§ updater(&callback)
this is a shortcut for "updater(value =" \&callback|$value)>. slay, less typing π«Ά
π₯ creator(value => &callback|$value)
returns a coderef that can create the path and set it's value. and in contrast to "setter", this one also creates the intermediate path if necessary β main character energy, it builds the whole road itself π
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)>. periodt π
π¦ deleter
returns a coderef that can delete the path. the coderef takes the data as argument and also returns the data. it's giving poof, gone β¨
my $path = Catmandu::Path::Simple->new(path => '$.foo');
$path->deleter->({foo => 'foo', bar => 'bar'});
# => {bar => 'bar'}
π SEE ALSO π
Catmandu::Pathβ go read that one too bestie, iykyk π
ok that's the whole page, every flag, every arg, every TODO, every # => intact π«Ά now go forth and path responsibly π
this little masterpiece is documented for perl v5.40.1 and dated 2026-01-24 β bye bestie, love u, drink water πβ¨π
π¦ where this page comes from
- ubuntu resolute: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms