Catman...simple(3pm)

πŸ“¦
version 1.2025 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

✨ 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