Perinc...Result(3pm)

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

πŸ’– Perinci::Object::EnvResult β€” the whole vibe πŸ’–

okay bestie, so this is Perinci::Object::EnvResult, a page from the User Contributed Perl Documentation (yes, that manual). it's part of the Perinci-Object Perl distribution and honestly? it's giving organized. it's giving tidy little result objects. come sit with me 🫢


✨ VERSION ✨

this doc describes version 0.311 of Perinci::Object::EnvResult (from the Perl distribution Perinci-Object), and it was released on 2020-01-02. iconic behavior, truly πŸ’…


🌸 SYNOPSIS 🌸

here's the whole thing in action, no cap:

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

my $envres = Perinci::Object::EnvResult->new([200, "OK", [1, 2, 3]]);
dd $envres->is_success, # 1
   $envres->status,     # 200
   $envres->message,    # "OK"
   $envres->payload,    # [1, 2, 3]
   $envres->meta,       # undef
   $envres->as_struct;  # [200, "OK", [1, 2, 3]]

# setting status, message, result, extra
$envres->status(404);
$envres->message('Not found');
$envres->payload(undef);
$envres->meta({errno=>-100});

# shortcut: create a new OK result ([200, "OK"] or [200, "OK", $payload])
$envres = Perinci::Object::EnvResult->new_ok();
$envres = Perinci::Object::EnvResult->new_ok(42);

like look at that. every getter is also a setter. main character energy fr fr πŸ’œ


πŸ¦‹ DESCRIPTION πŸ¦‹

so basically: this class gives you an object-oriented interface for an enveloped result (peep Rinci::function if you want the whole lore on what an enveloped result even is β€” that's where the details live).

that's it, that's the class. it wraps the array so you don't have to keep counting indexes with your eyeballs like some kind of medieval peasant 😭


πŸŽ€ METHODS πŸŽ€

new($res) => OBJECT

makes you a brand new object out of the $res enveloped result array. feed it the array, get a cute object back. slay ✨

new_ok([ $actual_res ]) => OBJECT

a shortcut, bestie!! it's literally just new([200,"OK",$actual_res]) β€” or if you don't pass $actual_res at all, it's new([200,"OK"]). so it's the "everything went great" starter pack 🌈

$envres->status

get or set the status β€” that's the 1st element. one method, two jobs, we love a multitasker πŸ‘‘

$envres->message

get or set the message β€” the 2nd element. πŸ“©

$envres->payload

get or set the actual payload β€” the 3rd element. this is the real content, the moment, the payload of the century πŸ“

$envres->meta

get or set the result metadata β€” the 4th element. the little side-notes, the lore, the extra credit πŸ’«

$envres->as_struct

hands you back the represented data structure. as in, the whole thing, back in array form. 🧚

$envres->is_success

returns true if the status is between 200-299. that's the happy zone, the green flags only zone πŸ’š


🌟 HOMEPAGE 🌟

go visit the project's homepage at <https://metacpan.org/release/Perinci-Object>. it's right there, go look πŸ‘€


🫢 SOURCE 🫢

the source repository lives at <https://github.com/perlancar/perl-Perinci-Object>. code is code, go read it πŸ’–


πŸ’€ BUGS πŸ’€

found a bug? got a feature request? please report it on the bugtracker website over at <https://github.com/perlancar/perl-Perinci-Object/issues>. do NOT just suffer in silence, that's not the vibe πŸ™ˆ

and when you do submit a bug or a request β€” please, please include a test-file, or a patch to an existing test-file, that shows off the bug or the feature you want. receipts make everything easier, fr fr.


πŸ‘‘ SEE ALSO πŸ‘‘

  • Perinci::Object

🌸 AUTHOR 🌸

perlancar <perlancar@cpan.org>


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

it's free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. periodt. πŸ’…


and that's the whole page bestie, no notes πŸ’–

okay so that's a wrap on Perinci::Object::EnvResult from Perl v5.36.0, dated 2022-10-13, and you absolutely ate this documentation. go build something cute with your enveloped results πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from