object key modifier works okay
[dbsrgits/DBIx-Class-ResultSet-WithMetaData.git] / lib / DBIx / Class / ResultSet / WithMetaData.pm
index 7e540c3..8b425be 100644 (file)
@@ -178,6 +178,16 @@ method display () {
       $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};
@@ -299,6 +309,39 @@ method _with_meta_hash ($modifier) {
   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