Perinc...ltMulti(3pm)

πŸ“¦
version 0.311 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Perinci::Object::EnvResultMulti β€” represent enveloped result (multistatus) πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation, living in section 3pm β€” Perinci::Object::EnvResultMulti, to be exact. If you've ever wanted your enveloped results to be like, per-item and detailed, this is the class that makes it happen. no cap. ✨


🌸 VERSION 🌸

This document describes version 0.311 of Perinci::Object::EnvResultMulti, which ships in the Perl distribution Perinci-Object, and it was released on 2020-01-02. πŸŽ€


✨ SYNOPSIS ✨

use Perinci::Object::EnvResultMulti;
use Data::Dump; # for dd()

sub myfunc {
    ...

    # if unspecified, the default status will be [200, "Success/no items"]
    my $envres = Perinci::Object::EnvResultMulti->new;

    # then you can add result for each item
    $envres->add_result(200, "OK", {item_id=>1});
    $envres->add_result(202, "OK", {item_id=>2, note=>"blah"});
    $envres->add_result(404, "Not found", {item_id=>3});
    ...

    # if you add a success status, the overall status will still be 200

    # if you add a non-success staus, the overall status will be 207, or
    # the non-success status (if no success has been added)

    # finally, return the result
    return $envres->as_struct;

    # the result from the above will be: [207, "Partial success", undef,
    # {results => [
    #     {success=>200, message=>"OK", item_id=>1},
    #     {success=>201, message=>"OK", item_id=>2, note=>"blah"},
    #     {success=>404, message=>"Not found", item_id=>3},
    # ]}]
} # myfunc

and if you wanna give each little result its own payload? say less πŸ‘‡

my $envres = Perinci::Object::EnvResultMulti->new;
$envres->add_result(200, "OK", {item_id=>1, payload=>"a"});
$envres->add_result(200, "OK", {item_id=>2, payload=>"b"});
$envres->add_result(200, "OK", {item_id=>3, payload=>"c"});

return $envres->as_struct;
# => [200, "All success", ["a","b","c"], ...]

πŸ’… DESCRIPTION πŸ’…

So basically, this class is a subclass of Perinci::Object::EnvResult, and its whole thing is being convenient when you want to use multistatus / detailed per-item results β€” the vibe that's specified in Rinci 1.1.63, aka the "results" result metadata property. πŸ¦‹

In that whole situation, the response status can be 200, 207, or non-success. And the way this class ate? As you keep adding more per-item results, it sets/updates the overall response status for you. it's giving personal assistant. periodt. πŸ‘‘


🧚 METHODS 🧚

⭐ new($res) => OBJECT

Spins up a brand new object from the $res enveloped result array. And if you don't pass $res at all? No worries, the default is literally [200, "Success/no items"]. cute, right? πŸ’–

⭐ $envres->add_result($status, $message, \%extra)

Adds an item result. That's it, that's the job. ✨

Extra keys you can sprinkle in there:

  • item_id
  • payload

Use this if you wanna add a payload for this result. The final overall payload will be an array composed from this payload. 🌈


πŸ‘‘ HOMEPAGE πŸ‘‘

Please visit the project's homepage at <https://metacpan.org/release/Perinci-Object>. 🫢


🌸 SOURCE 🌸

Source repository is at <https://github.com/perlancar/perl-Perinci-Object>. πŸ’œ


πŸ’€ BUGS πŸ’€

Please report any bugs or feature requests on the bugtracker website <https://github.com/perlancar/perl-Perinci-Object/issues>

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. (fr fr, it helps so much, don't just be like "it's broken" 😭)


🌈 SEE ALSO 🌈

  • Perinci::Object
  • Perinci::Object::EnvResult

πŸŽ€ AUTHOR πŸŽ€

perlancar <perlancar@cpan.org>


This software is copyright (c) 2021, 2017, 2016, 2015, 2014, 2013, 2012, 2011 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


and that's the whole page bestie, every last option and note intact, no details harmed in the making of this vibe check πŸ’…

okay so the footer deets, since you gotta know: this was the perl v5.36.0 manual, dated 2022-10-13, filed under Perinc...ltMulti(3pm). luv u, go write some multistatus results βœ¨πŸ¦‹πŸ’–

πŸ“¦ where this page comes from