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.pm34
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/DeWeave/WBO.pm b/lib/DeWeave/WBO.pm
index 3f551dd..bdfb027 100644
--- a/lib/DeWeave/WBO.pm
+++ b/lib/DeWeave/WBO.pm
@@ -4,6 +4,7 @@ use namespace::autoclean;
use MooseX::Types::Moose qw(Int Str Num);
use JSON::Any;
use Try::Tiny;
+use Data::Dump 'pp';
has id => (
isa => Str,
@@ -19,7 +20,7 @@ has modified => (
has sortindex => (
isa => Num,
- required => 1,
+ required => 0,
is => 'ro',
);
@@ -41,17 +42,30 @@ sub from_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;
- $args->{__crypt}=$crypt;
- };
+ use Data::Dump 'pp';warn pp $args;
+ if (defined $args->{payload}) {
+ $args->{__crypt}=$crypt;
}
- $class->new($args);
+ return $class->new($args);
}
+around BUILDARGS => sub {
+ my $orig = shift;
+ my $class = shift;
+
+ my $args = $class->$orig(@_);
+
+ return $args unless defined $args->{payload};
+
+ my $j = JSON::Any->new;
+ my $extra_args = $j->decode($args->{payload});
+
+ @$args{keys %$extra_args} =
+ values %$extra_args;
+
+ return $args;
+};
+
+
1;