/usr/share/perl5/Perinci/Object/EnvResult.pm is in libperinci-object-perl 0.13-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | package Perinci::Object::EnvResult;
use 5.010;
use strict;
use warnings;
our $VERSION = '0.13'; # VERSION
sub new {
my ($class, $res) = @_;
$res //= [0, "", undef];
my $obj = \$res;
bless $obj, $class;
}
sub new_ok {
my $class = shift;
my $res = [200, "OK"];
if (@_) {
push @$res, $_[0];
}
$class->new($res);
}
sub status {
my ($self, $new) = @_;
if (defined $new) {
die "Status must be an integer between 100 and 555" unless
int($new) eq $new && $new >= 100 && $new <= 555;
my $old = ${$self}->[0];
${$self}->[0] = $new;
return $old;
}
${$self}->[0];
}
sub message {
my ($self, $new) = @_;
if (defined $new) {
die "Extra must be a string" if ref($new);
my $old = ${$self}->[1];
${$self}->[1] = $new;
return $old;
}
${$self}->[1];
}
# avoid 'result' as this is ambiguous (the enveloped one? the naked one?). even
# avoid 'enveloped' (the payload being enveloped? the enveloped result
# (envelope+result inside)?)
sub payload {
my ($self, $new) = @_;
if (defined $new) {
my $old = ${$self}->[2];
${$self}->[2] = $new;
return $old;
}
${$self}->[2];
}
sub meta {
my ($self, $new) = @_;
if (defined $new) {
die "Extra must be a hashref" unless ref($new) eq 'HASH';
my $old = ${$self}->[3];
${$self}->[3] = $new;
return $old;
}
${$self}->[3];
}
sub is_success {
my ($self) = @_;
my $status = ${$self}->[0];
$status >= 200 && $status <= 299;
}
sub as_struct {
my ($self) = @_;
${$self};
}
1;
# ABSTRACT: Represent enveloped result
__END__
=pod
=encoding UTF-8
=head1 NAME
Perinci::Object::EnvResult - Represent enveloped result
=head1 VERSION
version 0.13
=head1 SYNOPSIS
use Perinci::Object::Result;
use Data::Dump; # for dd()
my $rires = Perinci::Object::Result->new([200, "OK", [1, 2, 3]]);
dd $rires->is_success, # 1
$rires->status, # 200
$rires->message, # "OK"
$rires->payload, # [1, 2, 3]
$rires->meta, # undef
$rires->as_struct; # [200, "OK", [1, 2, 3]]
# setting status, message, result, extra
$rires->status(404);
$rires->message('Not found');
$rires->payload(undef);
$rires->meta({errno=>-100});
# shortcut: create a new OK result ([200, "OK"] or [200, "OK", $payload])
$rires = Perinci::Object::Result->new_ok();
$rires = Perinci::Object::Result->new_ok(42);
=head1 DESCRIPTION
This class provides an object-oriented interface for enveloped result (see
L<Rinci::function> for more details).
=head1 METHODS
=head2 new($res) => OBJECT
Create a new object from $res enveloped result array.
=head2 $ssres->status
Get or set status (the 1st element).
=head2 $ssres->message
Get or set message (the 2nd element).
=head2 $ssres->payload
Get or set the actual payload (the 3rd element).
=head2 $ssres->meta
Get or set result metadata (the 4th element).
=head2 $ssres->as_struct
Return the represented data structure.
=head2 $ssres->is_success
True if status is between 200-299.
=head1 SEE ALSO
L<Perinci::Object>
=head1 HOMEPAGE
Please visit the project's homepage at L<https://metacpan.org/release/Perinci-Object>.
=head1 SOURCE
Source repository is at L<https://github.com/sharyanto/perl-Perinci-Object>.
=head1 BUGS
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Object>
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.
=head1 AUTHOR
Steven Haryanto <stevenharyanto@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|