summaryrefslogtreecommitdiff
path: root/lib/DeWeave/WBO.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/DeWeave/WBO.pm')
-rw-r--r--lib/DeWeave/WBO.pm56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/DeWeave/WBO.pm b/lib/DeWeave/WBO.pm
new file mode 100644
index 0000000..db89581
--- /dev/null
+++ b/lib/DeWeave/WBO.pm
@@ -0,0 +1,56 @@
+package DeWeave::WBO;
+use Moose;
+use namespace::autoclean;
+use MooseX::Types::Moose qw(Int Str Num);
+use JSON::Any;
+use Try::Tiny;
+
+has id => (
+ isa => Str,
+ required => 1,
+ is => 'ro',
+);
+
+has modified => (
+ isa => Num,
+ required => 1,
+ is => 'ro',
+);
+
+has sortindex => (
+ isa => Num,
+ required => 1,
+ is => 'ro',
+);
+
+has payload => (
+ isa => Str,
+ required => 1,
+ is => 'ro',
+);
+
+has ttl => (
+ isa => Int,
+ required => 0,
+ is => 'ro',
+);
+
+sub from_json {
+ my ($class,$json)=@_;
+
+ my $j = JSON::Any->new;
+
+ my $args = $j->decode($json);
+ if (exists $args->{payload}) {
+ try {
+ my $extra_args = $j->decode($args->{payload});
+
+ @$args{keys %$extra_args} =
+ values %$extra_args;
+ };
+ }
+
+ $class->new($args);
+}
+
+1;