$row->{$_} = $row_hash->{$_} for keys %{$row_hash};
}
+ foreach my $modifier (@{$rs->_object_hash_modifiers}) {
+ my $row_hash = $modifier->($row, $row_obj);
+ if (ref $row_hash ne 'HASH') {
+ die 'modifier subref (added via build_metadata) did not return hashref';
+ }
+
+ # simple merge for now, potentially needs to be more complex
+ $row->{$_} = $row_hash->{$_} for keys %{$row_hash};
+ }
+
foreach my $params (@{$rs->_key_modifiers}) {
my $modifier = $params->{modifier};
my $key = $params->{key};
return $rs;
}
+=head2 _with_object_meta_hash
+
+=over 4
+
+=item Arguments: subref($row_hash, $row_object)
+
+=item Return Value: ResultSet
+
+=back
+
+ $self->_with_object_meta_hash( sub {
+ my ($row_hash, $row_object) = @_;
+
+ my $return_hash = { substr => substr($row_object->name, 0, 3), substr2 => substr($row_hash->{name}, 0, 4) };
+ return $return_hash;
+ });
+
+Like L</_with_meta_hash> but the subref gets the row object
+as well as the row hash. This should only be used when you need to
+access row methods as it's slower to inflate objects.
+
+=cut
+
+method _with_object_meta_hash ($modifier) {
+ my $rs = $self->search({});
+ unless ($modifier && (ref $modifier eq 'CODE')) {
+ die 'build_metadata called without modifier param';
+ }
+
+ push( @{$rs->_object_hash_modifiers}, $modifier );
+ return $rs;
+}
+
=head2 add_row_info (DEPRECATED)
=over 4
}
{
+ my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr_multi_object->display();
+ is_deeply($artists, [
+ {
+ 'artistid' => '1',
+ 'name' => 'Caterwauler McCrae',
+ 'substr' => 'Cat',
+ 'substr2' => 'Cate'
+ },
+ {
+ 'artistid' => '2',
+ 'name' => 'Random Boy Band',
+ 'substr' => 'Ran',
+ 'substr2' => 'Rand'
+ },
+ {
+ 'artistid' => '3',
+ 'name' => 'We Are Goth',
+ 'substr' => 'We ',
+ 'substr2' => 'We A'
+ }
+ ], 'display with substring using _with_object_meta_hash okay');
+}
+
+{
my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr_key->display();
is_deeply($artists, [
{
'name' => 'We Are Goth',
'substr' => 'We '
}
- ], 'display with substring using _with_meta_key with object okay');
+ ], 'display with substring using _with_object_meta_key okay');
}
# {
return $self;
}
+method with_substr_multi_object () {
+ $self->_with_object_meta_hash(
+ sub {
+ my ($row_hash, $row_object) = @_;
+ my $substr = substr($row_object->name, 0, 3);
+ my $substr2 = substr($row_object->name, 0, 4);
+ my $row = {
+ substr => $substr,
+ substr2 => $substr2,
+ };
+ return $row;
+ }
+ );
+ return $self;
+}
+
method with_substr_key () {
$self->_with_meta_key(
substr => sub {