package Thing; use Data::Dumper; use Moose; has 'search' => ( is => 'rw', isa => 'HashRef', ); has '_data' => ( is => 'ro', isa => 'ArrayRef', traits => [ 'Array' ], default => sub { [] }, writer => '_add_data', reader => '_get_data', ); sub data { my ($self) = shift; if( @_ ) { my $stuff = shift; my $values = [ values %{ $self->search } ]; foreach my $row ( @{ $stuff } ) { print Dumper [ $row ]; print @{ $self->_get_data }, "\n"; print $row, "\n"; $self->_add_data( push @{ $self->_get_data }, $row ) if( scalar( grep { $_ ~~ $values } values %{ $row } ) > 1 ); } } else { return $self->_get_data; } } 1; #### #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use lib './'; use Thing; my $test = Thing->new; my $search = { 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four' }; $test->search( $search ); print Dumper $test->search; my $data = [{ thing => 'two', blah => 'barf', => other => 'four' }]; $test->data( $data ); $data = [{ thing => 'three', blah => 'one', => other => 'four', bl => "another", of => "something" }]; $test->data( $data ); print Dumper $test->data; #### $VAR1 = { '4' => 'four', '1' => 'one', '3' => 'three', '2' => 'two' }; $VAR1 = [ { 'blah' => 'barf', 'other' => 'four', 'thing' => 'two' } ]; HASH(0x1c48728) Attribute (_data) does not pass the type constraint because: Validation failed for 'ArrayRef' with value 1 at /Thing.pm line 30 Thing::data('Thing=HASH(0x1c41a68)', 'ARRAY(0x1caa868)') called at ./test.pl line 18 #### $VAR1 = [ { 'blah' => 'barf', 'other' => 'four', 'thing' => 'two' }, { 'blah' => 'one', 'of' => 'something', 'other' => 'four', 'thing' => 'three', 'bl' => 'another' } ];