From cb0e593bad1973d9ad301ea4c10daa8f3d12d5aa Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 24 Mar 2011 22:21:33 +0000 Subject: broken first stab --- lib/DeWeave/WBO.pm | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 lib/DeWeave/WBO.pm (limited to 'lib/DeWeave/WBO.pm') 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; -- cgit v1.2.3