5 BEGIN { $Data::Dumper::Sortkeys = 1 }; # so we can compare the deparsed coderefs below
13 my $schema = DBICTest->init_schema(no_deploy => 1);
15 my ($as, $vals, @pairs);
17 # artwork-artist deliberately mixed around
19 'artwork_to_artist.artist_id' => '2',
23 'artwork_to_artist.artwork_cd_id' => '1',
27 'cd.title' => 'Spoonful of bees',
29 'cd.artist.artistid' => '7',
30 'cd.artist.name' => 'Caterwauler McCrae',
31 'artwork_to_artist.artist.name' => 'xenowhinycide',
34 push @$as, shift @pairs;
35 push @$vals, shift @pairs;
38 my $parser = $schema->source ('Artwork')->_mk_row_parser($as, 'collapse requested');
48 artwork_to_artist => [
56 name => 'xenowhinycide',
59 [ 2, 1 ], # inherited from artwork_to_artist (child-parent definition)
62 [ 2, 1 ] # artwork_to_artist own data, in selection order
69 title => 'Spoonful of bees',
75 name => 'Caterwauler McCrae',
86 'generated row parser works as expected',
89 undef $_ for ($as, $vals);
91 'name' => 'Caterwauler McCrae',
92 'cds.tracks.cd' => '3',
93 'cds.tracks.title' => 'Fowlin',
94 'cds.tracks.cd_single.title' => 'Awesome single',
97 push @$as, shift @pairs;
98 push @$vals, shift @pairs;
100 $parser = $schema->source ('Artist')->_mk_row_parser($as);
106 name => 'Caterwauler McCrae'
120 title => 'Awesome single',
129 'generated parser works as expected over missing joins (no collapse)',
132 undef $_ for ($as, $vals);
134 'tracks.lyrics.lyric_versions.text' => 'unique when combined with the lyric collapsable by the 1:1 tracks-parent',
135 'existing_single_track.cd.artist.artistid' => 'artist_id (gives uniq. to its entire parent chain)',
136 'existing_single_track.cd.artist.cds.year' => 'non-unique cds col (year)',
137 'year' => 'non unique main year',
138 'genreid' => 'non-unique/nullable main genid',
139 'tracks.title' => 'non-unique title (missing multicol const. part)',
140 'existing_single_track.cd.artist.cds.cdid' => 'cds unique id col to give uniquiness to ...tracks.title below',
141 'latest_cd' => 'random function (not a colname)',
142 'existing_single_track.cd.artist.cds.tracks.title' => 'unique track title (when combined with ...cds.cdid above)',
143 'existing_single_track.cd.artist.cds.genreid' => 'nullable cds col (genreid)',
146 push @$as, shift @pairs;
147 push @$vals, shift @pairs;
151 $schema->source ('CD')->_resolve_collapse ( { map { $as->[$_] => $_ } (0 .. $#$as) } ),
154 'existing_single_track.cd.artist.artistid' => 1,
157 existing_single_track => {
159 'existing_single_track.cd.artist.artistid' => 1,
164 'existing_single_track.cd.artist.artistid' => 1,
169 'existing_single_track.cd.artist.artistid' => 1,
174 'existing_single_track.cd.artist.cds.cdid' => 6,
179 'existing_single_track.cd.artist.cds.cdid' => 6,
180 'existing_single_track.cd.artist.cds.tracks.title' => 8,
189 'existing_single_track.cd.artist.artistid' => 1,
195 'existing_single_track.cd.artist.artistid' => 1,
201 'existing_single_track.cd.artist.artistid' => 1,
203 'tracks.lyrics.lyric_versions.text' => 0,
209 'Correct collapse map constructed',
213 $parser = $schema->source ('CD')->_mk_row_parser ($as, 'add collapse data');
219 latest_cd => 'random function (not a colname)',
220 year => 'non unique main year',
221 genreid => 'non-unique/nullable main genid'
224 existing_single_track => [
231 { artistid => 'artist_id (gives uniq. to its entire parent chain)' },
235 cdid => 'cds unique id col to give uniquiness to ...tracks.title below',
236 year => 'non-unique cds col (year)',
237 genreid => 'nullable cds col (genreid)'
242 title => 'unique track title (when combined with ...cds.cdid above)'
246 'cds unique id col to give uniquiness to ...tracks.title below',
247 'unique track title (when combined with ...cds.cdid above)',
251 [ 'cds unique id col to give uniquiness to ...tracks.title below' ],
254 [ 'artist_id (gives uniq. to its entire parent chain)' ],
257 [ 'artist_id (gives uniq. to its entire parent chain)' ],
260 [ 'artist_id (gives uniq. to its entire parent chain)' ],
264 title => 'non-unique title (missing multicol const. part)'
272 text => 'unique when combined with the lyric collapsable by the 1:1 tracks-parent',
276 'unique when combined with the lyric collapsable by the 1:1 tracks-parent',
277 'artist_id (gives uniq. to its entire parent chain)',
278 'non-unique title (missing multicol const. part)',
283 'artist_id (gives uniq. to its entire parent chain)',
284 'non-unique title (missing multicol const. part)',
289 'artist_id (gives uniq. to its entire parent chain)',
290 'non-unique title (missing multicol const. part)',
294 [ 'artist_id (gives uniq. to its entire parent chain)' ],
296 'Proper row parser constructed',
299 # For extra insanity test/showcase the parser's guts:
300 my $deparser = B::Deparse->new;
302 $deparser->coderef2text ($parser),
303 $deparser->coderef2text ( sub { package DBIx::Class::ResultSource;
307 latest_cd => $_[0][7],
312 existing_single_track => [
324 !defined($_[0][6]) ? () : (
333 !defined($_[0][8]) ? () : (
339 [ $_[0][6], $_[0][8] ]
356 !defined($_[0][5]) ? () : (
367 !defined($_[0][0]) ? () : (
373 [ $_[0][0], $_[0][1], $_[0][5] ],
377 [ $_[0][1], $_[0][5] ],
381 [ $_[0][1], $_[0][5] ],
387 'Deparsed version of the parser coderef looks correct',