[Bast-commits] r3348 - trunk/DBIx-Class/lib/DBIx/Class/Manual
ilmari at dev.catalyst.perl.org
ilmari at dev.catalyst.perl.org
Mon May 21 21:23:37 GMT 2007
Author: ilmari
Date: 2007-05-21 21:23:36 +0100 (Mon, 21 May 2007)
New Revision: 3348
Modified:
trunk/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod
Log:
Copy the working mk_hash from HashRefInflator in -current into Cookbook
Modified: trunk/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod
===================================================================
--- trunk/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod 2007-05-21 20:21:44 UTC (rev 3347)
+++ trunk/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod 2007-05-21 20:23:36 UTC (rev 3348)
@@ -1172,8 +1172,26 @@
sub mk_hash {
my ($me, $rest) = @_;
- return { %$me,
- map { ($_ => mk_hash(@{$rest->{$_}})) } keys %$rest
+ # to avoid emtpy has_many rels contain one empty hashref
+ return if (not keys %$me);
+
+ my $def;
+
+ foreach (values %$me) {
+ if (defined $_) {
+ $def = 1;
+ last;
+ }
+ }
+ return unless $def;
+
+ return { %$me,
+ map {
+ ( $_ =>
+ ref($rest->{$_}[0]) eq 'ARRAY' ? [ map { mk_hash(@$_) } @{$rest->{$_}} ]
+ : mk_hash( @{$rest->{$_}} )
+ )
+ } keys %$rest
};
}
More information about the Bast-commits
mailing list