.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Perinci::Object::EnvResultMulti 3pm" .TH Perinci::Object::EnvResultMulti 3pm "2022-10-13" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Perinci::Object::EnvResultMulti \- Represent enveloped result (multistatus) .SH "VERSION" .IX Header "VERSION" This document describes version 0.311 of Perinci::Object::EnvResultMulti (from Perl distribution Perinci-Object), released on 2020\-01\-02. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& 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 .Ve .PP To add a payload for each result: .PP .Vb 4 \& 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"], ...] .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This class is a subclass of Perinci::Object::EnvResult and provides a convenience method when you want to use multistatus/detailed per-item results (specified in Rinci 1.1.63: \f(CW\*(C`results\*(C'\fR result metadata property). In this case, response status can be 200, 207, or non-success. As you add more per-item results, this class will set/update the overall response status for you. .SH "METHODS" .IX Header "METHODS" .SS "new($res) => \s-1OBJECT\s0" .IX Subsection "new($res) => OBJECT" Create a new object from \f(CW$res\fR enveloped result array. If \f(CW$res\fR is not specified, the default is \f(CW\*(C`[200, "Success/no items"]\*(C'\fR. .ie n .SS "$envres\->add_result($status, $message, \e%extra)" .el .SS "\f(CW$envres\fP\->add_result($status, \f(CW$message\fP, \e%extra)" .IX Subsection "$envres->add_result($status, $message, %extra)" Add an item result. .PP Extra keys: .IP "\(bu" 4 item_id .IP "\(bu" 4 payload .Sp If you want to add a payload for this result. The final overall payload will be an array composed from this payload. .SH "HOMEPAGE" .IX Header "HOMEPAGE" Please visit the project's homepage at . .SH "SOURCE" .IX Header "SOURCE" Source repository is at . .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests on the bugtracker website .PP 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. .SH "SEE ALSO" .IX Header "SEE ALSO" Perinci::Object .PP Perinci::Object::EnvResult .SH "AUTHOR" .IX Header "AUTHOR" perlancar .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2021, 2017, 2016, 2015, 2014, 2013, 2012, 2011 by perlancar@cpan.org. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.