object key modifier works okay
[dbsrgits/DBIx-Class-ResultSet-WithMetaData.git] / t / lib / DBICTest / Schema / ResultSet / Artist.pm
1 package DBICTest::Schema::ResultSet::Artist;
2
3 use Moose;
4 use Method::Signatures::Simple;
5 extends 'DBICTest::Schema::ResultSet';
6
7 method with_substr_multi () {
8   $self->_with_meta_hash( 
9     sub {
10       my $row = shift;
11       my $substr = substr($row->{name}, 0, 3);
12       my $substr2 = substr($row->{name}, 0, 4);
13       $row->{substr} = $substr;
14       $row->{substr2} = $substr2;
15       return $row;
16     }
17   );
18   return $self;
19 }
20
21 method with_substr_multi_object () {
22   $self->_with_object_meta_hash( 
23     sub {
24       my ($row_hash, $row_object) = @_;
25       my $substr = substr($row_object->name, 0, 3);
26       my $substr2 = substr($row_object->name, 0, 4);
27       my $row = {
28         substr => $substr,
29         substr2 => $substr2,
30       };
31       return $row;
32     }
33   );
34   return $self;
35 }
36
37 method with_substr_key () {
38   $self->_with_meta_key( 
39     substr => sub {
40       return substr(shift->{name}, 0, 3);
41     }
42   );
43   return $self;
44 }
45
46 method with_substr_key_obj () {
47   $self->_with_object_meta_key( 
48     substr => sub {
49       my ($hash, $obj) = @_;
50       return substr($obj->name, 0, 3);
51     }
52   );
53   return $self;
54 }
55
56 method with_substr_old () {
57   foreach my $row ($self->all) {
58     my $substr = substr($row->name, 0, 3);
59     $self->add_row_info(row => $row, info => { substr => $substr });
60   }
61   return $self;
62 }
63
64 1;