From c9af26b1194f693cd55fd9a7850bc168aeba7d27 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 27 Mar 2011 14:33:59 +0100 Subject: rework object creation now we unpack args before calling ->new --- lib/DeWeave/Collection.pm | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/DeWeave/Collection.pm') diff --git a/lib/DeWeave/Collection.pm b/lib/DeWeave/Collection.pm index 6ad87eb..874ea94 100644 --- a/lib/DeWeave/Collection.pm +++ b/lib/DeWeave/Collection.pm @@ -43,20 +43,27 @@ sub from_json { DEBUG '$args ',{filter=>\&pp,value=>$args}; - my @items; + my @items;my %deletions; for my $input_item (@$args) { - my $item; - try { - $item = $class->item_class->new({%$input_item,__crypt=>$crypt}) + my $item_args = DeWeave::WBO->unpack_args($input_item,$crypt); + + if (exists $item_args->{deleted}) { + $deletions{$item_args->{id}}=undef; + next; } - catch { - die $_ unless ref($_) && $_->isa('DeWeave::Exception::Deleted'); - }; + + # the $item_args is passed to allow subclasses to + # generate objects of different types for different inputs + my $item = $class->item_class($item_args) + ->new($item_args); + push @items,$item if $item; } + @items = grep { ! exists $deletions{$_->id} } @items; + return $class->new({ items => \@items, }); -- cgit v1.2.3