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