From: Matt S Trout Date: Fri, 19 Sep 2008 12:39:23 +0000 (+0000) Subject: removed retarded global; if you want this feature, make it a bloody constructor argum... X-Git-Tag: v0.08240~355 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4613ee1e805f722e186dff43738ab63603890b87;p=dbsrgits%2FDBIx-Class.git removed retarded global; if you want this feature, make it a bloody constructor argument, what I'm deleting is -not- DBIC core quality code --- diff --git a/lib/DBIx/Class/ResultClass/HashRefInflator.pm b/lib/DBIx/Class/ResultClass/HashRefInflator.pm index fb35d13..945bcfd 100644 --- a/lib/DBIx/Class/ResultClass/HashRefInflator.pm +++ b/lib/DBIx/Class/ResultClass/HashRefInflator.pm @@ -3,9 +3,6 @@ package DBIx::Class::ResultClass::HashRefInflator; use strict; use warnings; -our %inflator_cache; -our $inflate_data; - =head1 NAME DBIx::Class::ResultClass::HashRefInflator @@ -64,7 +61,6 @@ sub inflate_result { my ($self, $source, $me, $prefetch) = @_; my $hashref = mk_hash($me, $prefetch); - inflate_hash ($source->schema, $source->result_class, $hashref) if $inflate_data; return $hashref; } @@ -108,45 +104,6 @@ sub mk_hash { } } -=head2 inflate_hash - -This walks through a hashref produced by L and inflates any data -for which there is a registered inflator in the C - -=cut - -sub inflate_hash { - my ($schema, $rc, $data) = @_; - - foreach my $column (keys %{$data}) { - - if (ref $data->{$column} eq 'HASH') { - inflate_hash ($schema, $schema->source ($rc)->related_class ($column), $data->{$column}); - } - elsif (ref $data->{$column} eq 'ARRAY') { - foreach my $rel (@{$data->{$column}}) { - inflate_hash ($schema, $schema->source ($rc)->related_class ($column), $rel); - } - } - else { - # "null is null is null" - next if not defined $data->{$column}; - - # cache the inflator coderef - unless (exists $inflator_cache{$rc}{$column}) { - $inflator_cache{$rc}{$column} = exists $schema->source ($rc)->_relationships->{$column} - ? undef # currently no way to inflate a column sharing a name with a rel - : $rc->column_info($column)->{_inflate_info}{inflate} - ; - } - - if ($inflator_cache{$rc}{$column}) { - $data->{$column} = $inflator_cache{$rc}{$column}->($data->{$column}); - } - } - } -} - =head1 CAVEAT This will not work for relationships that have been prefetched. Consider the diff --git a/t/68inflate_resultclass_hashrefinflator.t b/t/68inflate_resultclass_hashrefinflator.t index a450c0e..a0402a1 100644 --- a/t/68inflate_resultclass_hashrefinflator.t +++ b/t/68inflate_resultclass_hashrefinflator.t @@ -131,9 +131,3 @@ $cd_rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); my $cd = $cd_rs->first; ok ( (not blessed $cd->{year}), "Plain string returned for year"); is ( $cd->{year}, '1997', "We are looking at the right year"); - -# try it again with inflation requested -local $DBIx::Class::ResultClass::HashRefInflator::inflate_data = 1; -my $cd2 = $cd_rs->first; -isa_ok ($cd2->{year}, 'DateTime', "Inflated object"); -is ($cd2->{year}, DateTime->new ( year => 1997 ), "Correct year was inflated");