10 my $schema = DBICTest->init_schema(no_deploy => 1);
12 my ($as, $vals, @pairs);
14 # artwork-artist deliberately mixed around
16 'artwork_to_artist.artist_id' => '2',
20 'artwork_to_artist.artwork_cd_id' => '1',
24 'cd.title' => 'Spoonful of bees',
26 'cd.artist.artistid' => '7',
27 'cd.artist.name' => 'Caterwauler McCrae',
28 'artwork_to_artist.artist.name' => 'xenowhinycide',
31 push @$as, shift @pairs;
32 push @$vals, shift @pairs;
37 my $parser = $schema->source ('Artwork')->_mk_row_parser({
50 artwork_to_artist => [
58 name => 'xenowhinycide',
61 [ 2, 1 ], # inherited from artwork_to_artist (child-parent definition)
64 [ 2, 1 ] # artwork_to_artist own data, in selection order
71 title => 'Spoonful of bees',
77 name => 'Caterwauler McCrae',
88 'generated row parser works as expected',
93 undef $_ for ($as, $vals);
95 'name' => 'Caterwauler McCrae',
96 'cds.tracks.cd' => '3',
97 'cds.tracks.title' => 'Fowlin',
98 'cds.tracks.cd_single.title' => 'Awesome single',
101 push @$as, shift @pairs;
102 push @$vals, shift @pairs;
104 $parser = $schema->source ('Artist')->_mk_row_parser($as);
110 name => 'Caterwauler McCrae'
124 title => 'Awesome single',
133 'generated parser works as expected over missing joins (no collapse)',
138 undef $_ for ($as, $vals);
140 'tracks.lyrics.lyric_versions.text' => 'unique when combined with the lyric collapsable by the 1:1 tracks-parent',
141 'existing_single_track.cd.artist.artistid' => 'artist_id (gives uniq. to its entire parent chain)',
142 'existing_single_track.cd.artist.cds.year' => 'non-unique cds col (year)',
143 'year' => 'non unique main year',
144 'genreid' => 'non-unique/nullable main genid',
145 'tracks.title' => 'non-unique title (missing multicol const. part)',
146 'existing_single_track.cd.artist.cds.cdid' => 'cds unique id col to give uniquiness to ...tracks.title below',
147 'latest_cd' => 'random function (not a colname)',
148 'existing_single_track.cd.artist.cds.tracks.title' => 'unique track title (when combined with ...cds.cdid above)',
149 'existing_single_track.cd.artist.cds.genreid' => 'nullable cds col (genreid)',
152 push @$as, shift @pairs;
153 push @$vals, shift @pairs;
157 $schema->source ('CD')->_resolve_collapse ( { map { $as->[$_] => $_ } (0 .. $#$as) } ),
160 -node_id => [ 1 ], # existing_single_track.cd.artist.artistid
161 -branch_id => [ 0, 1, 5, 6, 8 ],
163 existing_single_track => {
165 -node_id => [ 1 ], # existing_single_track.cd.artist.artistid
166 -branch_id => [ 1, 6, 8 ],
171 -node_id => [ 1 ], # existing_single_track.cd.artist.artistid
172 -branch_id => [ 1, 6, 8 ],
177 -node_id => [ 1 ], # existing_single_track.cd.artist.artistid
178 -branch_id => [ 1, 6, 8 ],
183 -node_id => [ 6 ], # existing_single_track.cd.artist.cds.cdid
184 -branch_id => [ 6, 8 ],
189 -node_id => [ 6, 8 ], # existing_single_track.cd.artist.cds.cdid, existing_single_track.cd.artist.cds.tracks.title
190 -branch_id => [ 6, 8 ],
199 -node_id => [ 1, 5 ], # existing_single_track.cd.artist.artistid, tracks.title
200 -branch_id => [ 0, 1, 5 ],
205 -node_id => [ 1, 5 ], # existing_single_track.cd.artist.artistid, tracks.title
206 -branch_id => [ 0, 1, 5 ],
212 -node_id => [ 0, 1, 5 ], # tracks.lyrics.lyric_versions.text, existing_single_track.cd.artist.artistid, tracks.title
213 -branch_id => [ 0, 1, 5 ],
219 'Correct collapse map constructed',
226 my $parser = $schema->source ('CD')->_mk_row_parser ({ inflate_map => $as, collapse => 1 });
234 latest_cd => 'random function (not a colname)',
235 year => 'non unique main year',
236 genreid => 'non-unique/nullable main genid'
239 existing_single_track => [
246 { artistid => 'artist_id (gives uniq. to its entire parent chain)' },
250 cdid => 'cds unique id col to give uniquiness to ...tracks.title below',
251 year => 'non-unique cds col (year)',
252 genreid => 'nullable cds col (genreid)'
257 title => 'unique track title (when combined with ...cds.cdid above)'
261 'cds unique id col to give uniquiness to ...tracks.title below',
262 'unique track title (when combined with ...cds.cdid above)',
266 [ 'cds unique id col to give uniquiness to ...tracks.title below' ],
269 [ 'artist_id (gives uniq. to its entire parent chain)' ],
272 [ 'artist_id (gives uniq. to its entire parent chain)' ],
275 [ 'artist_id (gives uniq. to its entire parent chain)' ],
279 title => 'non-unique title (missing multicol const. part)'
287 text => 'unique when combined with the lyric collapsable by the 1:1 tracks-parent',
291 'unique when combined with the lyric collapsable by the 1:1 tracks-parent',
292 'artist_id (gives uniq. to its entire parent chain)',
293 'non-unique title (missing multicol const. part)',
298 'artist_id (gives uniq. to its entire parent chain)',
299 'non-unique title (missing multicol const. part)',
304 'artist_id (gives uniq. to its entire parent chain)',
305 'non-unique title (missing multicol const. part)',
309 [ 'artist_id (gives uniq. to its entire parent chain)' ],
311 'Proper row parser constructed',
316 # For extra insanity test/showcase the parser's guts:
317 my $deparser = B::Deparse->new;
319 $deparser->coderef2text ($parser),
320 $deparser->coderef2text ( sub { package DBIx::Class::ResultSource;
323 my $r = (shift @{$_[0]->{row_stash}}) || ($_[0]->{next_row} and $_[0]->{next_row}->()) || last;
332 latest_cd => $_[0][7],
337 existing_single_track => [
349 !defined($_[0][6]) ? () : (
358 !defined($_[0][8]) ? () : (
364 [ $_[0][6], $_[0][8] ]
381 !defined($_[0][5]) ? () : (
392 !defined($_[0][0]) ? () : (
398 [ $_[0][0], $_[0][1], $_[0][5] ],
402 [ $_[0][1], $_[0][5] ],
406 [ $_[0][1], $_[0][5] ],
412 'Deparsed version of the parser coderef looks correct',