], 'display with substring using _with_meta_key okay');
}
+{
+ my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr_key_obj->display();
+ is_deeply($artists, [
+ {
+ 'artistid' => '1',
+ 'name' => 'Caterwauler McCrae',
+ 'substr' => 'Cat'
+ },
+ {
+ 'artistid' => '2',
+ 'name' => 'Random Boy Band',
+ 'substr' => 'Ran'
+ },
+ {
+ 'artistid' => '3',
+ 'name' => 'We Are Goth',
+ 'substr' => 'We '
+ }
+ ], 'display with substring using _with_meta_key with object okay');
+}
+
# {
# my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr_old->display();
# is_deeply($artists, [
return $self;
}
+method with_substr_key_obj () {
+ $self->_with_meta_key(
+ substr => sub {
+ my ($hash, $obj) = @_;
+ return substr($obj->name, 0, 3);
+ }
+ );
+ return $self;
+}
+
method with_substr_old () {
foreach my $row ($self->all) {
my $substr = substr($row->name, 0, 3);