new Client/Router/Service arch
[scpubgit/Tak.git] / lib / Tak / Result.pm
diff --git a/lib/Tak/Result.pm b/lib/Tak/Result.pm
new file mode 100644 (file)
index 0000000..a7afb4f
--- /dev/null
@@ -0,0 +1,24 @@
+package Tak::Result;
+
+use Moo;
+
+has type => (is => 'ro', required => 1);
+has data => (is => 'ro', required => 1);
+
+sub get {
+  my ($self) = @_;
+  $self->throw unless $self->type eq 'success';
+  return wantarray ? @{$self->data} : $self->data->[0];
+}
+
+sub throw {
+  my ($self) = @_;
+  die $self->exception;
+}
+
+sub exception {
+  my ($self) = @_;
+  $self->type.': '.join ' ', @{$self->data};
+}
+
+1;