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 | ||
8 | sub get { | |
9 | my ($self) = @_; | |
10 | $self->throw unless $self->type eq 'success'; | |
11 | return wantarray ? @{$self->data} : $self->data->[0]; | |
12 | } | |
13 | ||
14 | sub throw { | |
15 | my ($self) = @_; | |
16 | die $self->exception; | |
17 | } | |
18 | ||
19 | sub exception { | |
20 | my ($self) = @_; | |
21 | $self->type.': '.join ' ', @{$self->data}; | |
22 | } | |
23 | ||
24 | 1; |