Rinci::FAQ - Metadata for your functions/methods
This document describes version 1.1.61 of Rinci::FAQ (from Perl distribution Rinci), released on 2014-10-22.
Why do you make enveloped result an arary instead of hash?
For example, a hash-based enveloped result can be something like:
{status=>200, message=>"OK", result=>42, meta1=>..., meta2=>...}
This has the benefit of a single container, but I picked array because of the brevity for simple cases (which are the majority), e.g.:
[200] # versus {status=>200} [200, "OK"] # versus {status=>200, message=>"OK"}
When handling enveloped result, the array version is also shorter:
if ($res->[0] == 200) { ... } # versus: if ($res->{status} == 200) { ... } print "Error $res->[0] - $res->[1]"; # versus: print "Error $res->{status} - $res->{message}";
The hash version is more obvious for first-time reader, but after just some amount of time, $res->[0], $res->[1] will become obvious if you use it consistently.
$res->[0]
$res->[1]
As a bonus, arrays are faster and more space-efficient than hashes.
How do you indicate transient/temporary vs permanent errors?
Some protocols, like SMTP or POP, defines 4xx codes as temporary errors and 5xx as permanent ones. This gives clue to clients whether to retry or not. HTTP, which Rinci is modelled after, does not provide such distinction to its status codes. However, Rinci defines a perm_err result metadata that can be used for such purpose, e.g.:
perm_err
[500, "Can't submit mail, we are being blocked by RBL", undef, {perm_err=>0}] [500, "Can't submit mail, destination address does not exist", undef, {perm_err=>1}]
Please visit the project's homepage at https://metacpan.org/release/Rinci.
Source repository is at https://github.com/perlancar/perl-Rinci.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Rinci
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.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2014 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.
To install Rinci, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Rinci
CPAN shell
perl -MCPAN -e shell install Rinci
For more information on module installation, please visit the detailed CPAN module installation guide.