From 177c4e9d4e65906ce00af379fbb2ac561041e8bc Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 9 Dec 2009 02:05:55 +0000 Subject: [PATCH] improve de-nastification for lists --- Changes | 3 +++ lib/Net/OpenSRS.pm | 33 ++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index 6df9503..5c4d457 100644 --- a/Changes +++ b/Changes @@ -8,3 +8,6 @@ 0.03 Tue Sep 1 2009 - Ugly fix for Expat parser error due to spaces in an element name in the OpenSRS renew domain response. + +0.04 + - Correct de-nastification to handle lists diff --git a/lib/Net/OpenSRS.pm b/lib/Net/OpenSRS.pm index 47150d3..2b74009 100644 --- a/lib/Net/OpenSRS.pm +++ b/lib/Net/OpenSRS.pm @@ -1166,7 +1166,13 @@ XML my $rslt = $res->content; # OpenSRS renew response triggers Expat parser error due to spaces in element name $rslt =~ s/registration expiration date/registration_expiration_date/g; - eval { $struct = XML::Simple::XMLin( $rslt ); }; + + eval { $struct = XML::Simple::XMLin( + $rslt, + 'KeyAttr' => [ 'dt_assoc' ], + 'GroupTags' => { 'dt_assoc' => 'item', 'dt_array' => 'item' }, + ); + }; if ($self->debug_level > 1) { $self->debug("\nOpenSRS Response XML:\n" . '-' x 30); @@ -1176,10 +1182,7 @@ XML # get the struct looking just how we want it. # (de-nastify it.) - $xml = XML::Simple::XMLout( $struct->{body}->{data_block}->{dt_assoc}->{item} ); - $struct = XML::Simple::XMLin( $xml ); - $xml = XML::Simple::XMLout( $struct->{attributes}->{item} ); - $struct->{attributes} = XML::Simple::XMLin( $xml ); + (undef, $struct) = _denastify( $struct->{body}->{data_block} ); } else { $self->debug("HTTP error: " . $res->status_line); @@ -1229,6 +1232,26 @@ sub _format return $xml; } +sub _denastify { + my ($arg) = ( shift ); + if ( ref($arg) eq 'HASH' ) { + my $value; + if ( exists( $arg->{content} ) ) { + $value = $arg->{content}; + } elsif ( exists( $arg->{dt_array} ) ) { + $value = [ map { + { map { _denastify($_) } @{ $_->{dt_assoc} } } + } + @{ $arg->{dt_array} } + ]; + } elsif ( exists( $arg->{dt_assoc} ) ) { + $value = { map { _denastify($_) } @{ $arg->{dt_assoc} } }; + } + return ( $arg->{key} => $value ); + } + (); +} + =back =head1 Author -- 2.11.0