new remote code
[scpubgit/Tak.git] / lib / Tak / Result.pm
CommitLineData
31a246e4 1package Tak::Result;
2
3use Moo;
4
5has type => (is => 'ro', required => 1);
6has data => (is => 'ro', required => 1);
7
77bf1d9b 8sub flatten { $_[0]->type, @{$_[0]->data} }
9
31a246e4 10sub get {
11 my ($self) = @_;
12 $self->throw unless $self->type eq 'success';
13 return wantarray ? @{$self->data} : $self->data->[0];
14}
15
16sub throw {
17 my ($self) = @_;
18 die $self->exception;
19}
20
21sub exception {
22 my ($self) = @_;
23 $self->type.': '.join ' ', @{$self->data};
24}
25
261;