a7afb4f554a13266c3240fe6659d78d9a0e491c9
[scpubgit/Tak.git] / lib / Tak / Result.pm
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;