@@ -211,7 +211,8 @@ my %OBJECT_HANDLERS = (
211211);
212212
213213
214- my %TYPES = (
214+ my %TYPES ;
215+ %TYPES = (
215216 # NOTE:
216217 # we need to make sure that we properly numify the numbers
217218 # before and after them being futzed with, because some of
@@ -237,9 +238,17 @@ my %TYPES = (
237238 expand => sub {
238239 my ( $array , @args ) = @_ ;
239240 foreach my $i (0 .. $# {$array }) {
240- next unless ref ($array -> [$i ]) eq ' HASH'
241- && exists $array -> [$i ]-> {$CLASS_MARKER };
242- $array -> [$i ] = $OBJECT_HANDLERS {expand }-> ($array -> [$i ], @args );
241+ if (ref ($array -> [$i ]) eq ' HASH' ) {
242+ if (exists ($array -> [$i ]{$CLASS_MARKER })) {
243+ $array -> [$i ] = $OBJECT_HANDLERS {expand }-> ($array -> [$i ], @args );
244+ }
245+ else {
246+ $array -> [$i ] = $TYPES {HashRef }{expand }-> ($array -> [$i ], @args );
247+ }
248+ }
249+ elsif (ref ($array -> [$i ]) eq ' ARRAY' ) {
250+ $array -> [$i ] = $TYPES {ArrayRef }{expand }-> ($array -> [$i ], @args );
251+ }
243252 }
244253 $array ;
245254 },
@@ -252,6 +261,8 @@ my %TYPES = (
252261 [ map {
253262 blessed($_ )
254263 ? $OBJECT_HANDLERS {collapse }-> ($_ , @args )
264+ : $TYPES {ref ($_ )}
265+ ? $TYPES {ref ($_ )}-> {collapse }-> ($_ , @args )
255266 : $_
256267 } @$array ]
257268 }
@@ -260,9 +271,17 @@ my %TYPES = (
260271 expand => sub {
261272 my ( $hash , @args ) = @_ ;
262273 foreach my $k (keys %$hash ) {
263- next unless ref ($hash -> {$k }) eq ' HASH'
264- && exists $hash -> {$k }-> {$CLASS_MARKER };
265- $hash -> {$k } = $OBJECT_HANDLERS {expand }-> ($hash -> {$k }, @args );
274+ if (ref ($hash -> {$k }) eq ' HASH' ) {
275+ if (exists ($hash -> {$k }-> {$CLASS_MARKER })) {
276+ $hash -> {$k } = $OBJECT_HANDLERS {expand }-> ($hash -> {$k }, @args );
277+ }
278+ else {
279+ $hash -> {$k } = $TYPES {HashRef }{expand }-> ($hash -> {$k }, @args );
280+ }
281+ }
282+ elsif (ref ($hash -> {$k }) eq ' ARRAY' ) {
283+ $hash -> {$k } = $TYPES {ArrayRef }{expand }-> ($hash -> {$k }, @args );
284+ }
266285 }
267286 $hash ;
268287 },
@@ -275,6 +294,8 @@ my %TYPES = (
275294 +{ map {
276295 blessed($hash -> {$_ })
277296 ? ($_ => $OBJECT_HANDLERS {collapse }-> ($hash -> {$_ }, @args ))
297+ : $TYPES {ref ($hash -> {$_ })}
298+ ? ($_ => $TYPES {ref ($hash -> {$_ })}{collapse }-> ($hash -> {$_ }, @args ))
278299 : ($_ => $hash -> {$_ })
279300 } keys %$hash }
280301 }
@@ -290,6 +311,13 @@ my %TYPES = (
290311 # }
291312);
292313
314+ %TYPES = (
315+ %TYPES ,
316+ ' HASH' => $TYPES {HashRef },
317+ ' ARRAY' => $TYPES {ArrayRef },
318+ );
319+
320+
293321sub add_custom_type_handler {
294322 my ($self , $type_name , %handlers ) = @_ ;
295323 (exists $handlers {expand } && exists $handlers {collapse })
0 commit comments