repl works again
[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
2791fd73 10sub is_success { $_[0]->type eq 'success' }
11
31a246e4 12sub get {
13 my ($self) = @_;
2791fd73 14 $self->throw unless $self->is_success;
31a246e4 15 return wantarray ? @{$self->data} : $self->data->[0];
16}
17
18sub throw {
19 my ($self) = @_;
20 die $self->exception;
21}
22
23sub exception {
24 my ($self) = @_;
25 $self->type.': '.join ' ', @{$self->data};
26}
27
281;