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/WBO.pm | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'lib/DeWeave/WBO.pm') diff --git a/lib/DeWeave/WBO.pm b/lib/DeWeave/WBO.pm index d38120f..0e1e6f8 100644 --- a/lib/DeWeave/WBO.pm +++ b/lib/DeWeave/WBO.pm @@ -41,6 +41,8 @@ has ttl => ( sub _debug_data { my ($self,$msg,$data) = @_; + return unless get_logger()->is_debug; + local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth+1; my %data_clean;my @keys_clean = grep {!/^_/} keys %$data; @@ -61,27 +63,34 @@ sub from_json { $class->_debug_data('$args ',$args); - if (defined $args->{payload}) { - $args->{__crypt}=$crypt; - } + $args = $class->unpack_args($args,$crypt); return $class->new($args); } -around BUILDARGS => sub { - my $orig = shift; - my $class = shift; - - my $args = $class->$orig(@_); +sub unpack_args { + my ($class,$args,$crypt) = @_; return $args unless defined $args->{payload}; my $j = JSON::Any->new; my $extra_args = $j->decode($args->{payload}); + my $decrypt_args = {}; + + if (defined $crypt && exists $extra_args->{ciphertext}) { + my $decrypted_payload = $crypt->decrypt($extra_args); + + if (defined $decrypted_payload) { + $decrypt_args = $j->decode($decrypted_payload); + } + } @$args{keys %$extra_args} = values %$extra_args; + @$args{keys %$decrypt_args} = + values %$decrypt_args; + delete @$args{grep {!defined $args->{$_}} keys %$args}; $class->_debug_data('buildargs: ',$args); -- cgit v1.2.3