Author: jkeenan Date: Fri Aug 31 18:53:12 2007 New Revision: 20977 Modified: trunk/config/gen/config_pm.pm trunk/lib/Parrot/Configure/Data.pm trunk/t/configure/032_data.t
Log: Applying patch submitted in http://rt.perl.org/rt3/Ticket/Display.html?id=44597A Refactor Parrot::Configure::dump() to eliminate dump_temp(), require 2 args, etc. As applied, patch differs slightly from that originally submitted, mainly due to renaming of data.t to 032-data.t. Modified: trunk/config/gen/config_pm.pm ============================================================================== --- trunk/config/gen/config_pm.pm (original) +++ trunk/config/gen/config_pm.pm Fri Aug 31 18:53:12 2007 @@ -51,8 +51,8 @@ print {$OUT} "# Generated by config/gen/config_pm.pm\n"; while (<$IN>) { - s/<<PCONFIG>>/$conf->data->dump()/e; - s/<<PCONFIGTEMP>>/$conf->data->dump_temp()/e; + s/<<PCONFIG>>/$conf->data->dump(q{c}, q{*PConfig})/e; + s/<<PCONFIGTEMP>>/$conf->data->dump(q{c_temp}, q{*PConfig_Temp})/e; print {$OUT} $_; } Modified: trunk/lib/Parrot/Configure/Data.pm ============================================================================== --- trunk/lib/Parrot/Configure/Data.pm (original) +++ trunk/lib/Parrot/Configure/Data.pm Fri Aug 31 18:53:12 2007 @@ -16,7 +16,7 @@ $data->set($key1 => $value1, $key2 => $value2); $data->add($delimiter, $key1 => $value1, $key2 => $value2); my @keys = $data->keys; - my $serialized = $data->dump; + my $serialized = $data->dump(q{c}, q{*PConfig}); $data->clean; $data->settrigger($key, $trigger, $cb); $data->gettriggers($key); @@ -217,54 +217,46 @@ =item C<dump()> Provides a L<Data::Dumper> serialized string of the objects key/value pairs -suitable for being C<eval>ed. The variable name of the structure is -C<PConfig>. +suitable for being C<eval>ed. -Accepts no arguments and returns a string. +Takes two arguments: -=cut +=over 4 -# Data::Dumper supports Sortkeys since 2.12 -# older versions will work but obviously not sorted -{ - if ( defined eval { Data::Dumper->can('Sortkeys') } ) { - *dump = sub { - my $self = shift; - Data::Dumper->new( [ $self->{c} ], ['*PConfig'] )->Sortkeys(1)->Dump(); - }; - } - else { - *dump = sub { - my $self = shift; - Data::Dumper->new( [ $self->{c} ], ['*PConfig'] )->Dump(); - }; - } -} +=item 1 -=item C<dump_temp()> +Key in Parrot::Configure object's data structure which is being dumped. -Provides a L<Data::Dumper> serialized string of the objects key/value pairs -suitable for being C<eval>ed. The variable name of the structure is -C<PConfig_Temp>. +=item 2 + +Name of the dumped structure. + +=back -Accepts no arguments and returns a string. +Example: + + $conf->data->dump(q{c}, q{*PConfig}); + $conf->data->dump(q{c_temp}, q{*PConfig_Temp}); + +Returns a string. =cut # Data::Dumper supports Sortkeys since 2.12 # older versions will work but obviously not sorted { - - if ( defined eval { Data::Dumper->can( 'Sortkeys' ) } ) { - *dump_temp = sub { + if ( defined eval { Data::Dumper->can('Sortkeys') } ) { + *dump = sub { my $self = shift; - Data::Dumper->new( [ $self->{c_temp} ], ['*PConfig_Temp'] )->Sortkeys(1)->Dump(); + my ($key, $structure) = @_; + Data::Dumper->new( [ $self->{$key} ], [$structure] )->Sortkeys(1)->Dump(); }; } else { - *dump_temp = sub { + *dump = sub { my $self = shift; - Data::Dumper->new( [ $self->{c_temp} ], ['*PConfig_Temp'] )->Dump(); + my ($key, $structure) = @_; + Data::Dumper->new( [ $self->{$key} ], [$structure] )->Dump(); }; } } Modified: trunk/t/configure/032_data.t ============================================================================== --- trunk/t/configure/032_data.t (original) +++ trunk/t/configure/032_data.t Fri Aug 31 18:53:12 2007 @@ -164,7 +164,7 @@ { my $pcd = Parrot::Configure::Data->new; - my $data = $pcd->dump; + my $data = $pcd->dump(q{c}, q{*PConfig}); like( $data, qr/\%PConfig = \(\);/, "->dump() returns nothing if no keys are set" ); } @@ -178,7 +178,8 @@ 'b' => 2, 'c' => 3, ); - my $data = $pcd->dump; + my $data = $pcd->dump(q{c}, q{*PConfig}); + like( $data,