Commit | Line | Data |
b0930c1e |
1 | package DBIx::Class::ResultClass::HashRefInflator; |
2 | |
3 | # $me is the hashref of cols/data from the immediate resultsource |
4 | # $rest is a deep hashref of all the data from the prefetched |
5 | # related sources. |
6 | |
7 | sub mk_hash { |
8 | my ($me, $rest) = @_; |
9 | |
10 | # to avoid emtpy has_many rels contain one empty hashref |
11 | return if (not keys %$me); |
12 | |
13 | return { %$me, |
14 | map { ($_ => ref($rest->{$_}[0]) eq 'ARRAY' ? [ map { mk_hash(@$_) } @{$rest->{$_}} ] : mk_hash(@{$rest->{$_}}) ) } keys %$rest |
15 | }; |
16 | } |
17 | |
18 | sub inflate_result { |
19 | my ($self, $source, $me, $prefetch) = @_; |
20 | |
21 | return mk_hash($me, $prefetch); |
22 | } |
23 | |
24 | 1; |