NAME

Perinci::Object::EnvResult - Represent enveloped result

VERSION

version 0.06

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);

DESCRIPTION

This class provides an object-oriented interface for enveloped result (see Rinci::function for more details).

METHODS

new($res) => OBJECT

Create a new object from $res enveloped result array.

$ssres->status

Get or set status (the 1st element).

$ssres->message

Get or set message (the 2nd element).

$ssres->payload

Get or set the actual payload (the 3rd element).

$ssres->meta

Get or set result metadata (the 4th element).

$ssres->as_struct

Return the represented data structure.

$ssres->is_success

True if status is between 200-299.

SEE ALSO

Perinci::Object

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 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.