From: Peter Rabbitson Date: Sun, 24 Feb 2013 10:41:58 +0000 (+0100) Subject: Do not rely on Data::Dumper to produce rolled out hashrefs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a8f62ee08;p=dbsrgits%2FDBIx-Class-Historic.git Do not rely on Data::Dumper to produce rolled out hashrefs --- diff --git a/lib/DBIx/Class/ResultSource/RowParser/Util.pm b/lib/DBIx/Class/ResultSource/RowParser/Util.pm index 4d833d3..22b4150 100644 --- a/lib/DBIx/Class/ResultSource/RowParser/Util.pm +++ b/lib/DBIx/Class/ResultSource/RowParser/Util.pm @@ -89,8 +89,7 @@ sub __visit_infmap_simple { } my $me_struct; - $me_struct = __visit_dump({ map { $_ => "\xFF__VALPOS__$my_cols->{$_}__\xFF" } (keys %$my_cols) }) - if keys %$my_cols; + $me_struct = __result_struct_to_source($my_cols) if keys %$my_cols; if ($args->{hri_style}) { $me_struct =~ s/^ \s* \{ | \} \s* $//gx @@ -226,8 +225,7 @@ sub __visit_infmap_collapse { } my $me_struct; - $me_struct = __visit_dump({ map { $_ => "\xFF__VALPOS__$my_cols->{$_}__\xFF" } (keys %$my_cols) }) - if keys %$my_cols; + $me_struct = __result_struct_to_source($my_cols) if keys %$my_cols; $me_struct = sprintf( '[ %s ]', $me_struct||'' ) unless $args->{hri_style}; @@ -335,27 +333,11 @@ sub __visit_infmap_collapse { ); } -# keep our own DD object around so we don't have to fitz with quoting -my $dumper_obj; -sub __visit_dump { - - # we actually will be producing functional perl code here, - # thus no second-guessing of what these globals might have - # been set to. DO NOT CHANGE! - ($dumper_obj ||= do { - require Data::Dumper; - Data::Dumper->new([]) - ->Useperl (0) - ->Purity (1) - ->Pad ('') - ->Useqq (0) - ->Terse (1) - ->Quotekeys (1) - ->Deepcopy (0) - ->Deparse (0) - ->Maxdepth (0) - ->Indent (0) # faster but harder to read, perhaps leave at 1 ? - })->Values ([$_[0]])->Dump; +sub __result_struct_to_source { + sprintf( '{ %s }', join (', ', map + { sprintf "%s => '\xFF__VALPOS__%d__\xFF'", perlstring($_), $_[0]{$_} } + sort keys %{$_[0]} + )); } 1; diff --git a/t/52leaks.t b/t/52leaks.t index 9a9a570..f1d11af 100644 --- a/t/52leaks.t +++ b/t/52leaks.t @@ -371,16 +371,6 @@ for my $slot (keys %$weak_registry) { delete $weak_registry->{$slot} unless $cleared->{hash_merge_singleton}{$weak_registry->{$slot}{weakref}{behavior}}++; } - elsif ( - $slot =~ /^Data::Dumper/ - and - $weak_registry->{$slot}{stacktrace} =~ /\QDBIx::Class::ResultSource::RowParser::_mk_row_parser/ - ) { - # there should be only one D::D object (used to construct the rowparser) - # more would indicate trouble - delete $weak_registry->{$slot} - unless $cleared->{mk_row_parser_dd_singleton}++; - } elsif ($slot =~ /^DateTime::TimeZone/) { # DT is going through a refactor it seems - let it leak zones for now delete $weak_registry->{$slot};