/usr/share/perl5/Search/GIN/Query/Attributes.pm is in libsearch-gin-perl 0.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | use strict;
use warnings;
package Search::GIN::Query::Attributes;
# ABSTRACT: Create attributes-based GIN queries
our $VERSION = '0.11';
use Moose;
use Carp qw(croak);
use namespace::autoclean;
with qw(
Search::GIN::Query
Search::GIN::Keys::Deep
);
has attributes => (
isa => "HashRef",
is => "rw",
required => 1,
);
has compare => (
isa => "Str|CodeRef",
is => "rw",
default => "compare_naive",
);
sub extract_values {
my $self = shift;
return (
method => "all",
values => [ $self->process_keys($self->attributes) ],
);
}
sub consistent {
my ( $self, $index, $obj ) = @_;
my $class = ref $obj;
my $meta = Class::MOP::get_metaclass_by_name($class);
my $query = $self->attributes;
my %got;
foreach my $attr_name ( keys %$query ) {
my $expected = $query->{$attr_name};
my $meta_attr = $meta->find_attribute_by_name($attr_name) || return;
$got{$attr_name} = $meta_attr->get_value($obj);
}
my $cmp = $self->compare;
return $self->$cmp( \%got, $query );
}
sub compare_naive {
my ( $self, $got, $exp ) = @_;
return unless keys %$got == keys %$exp;
foreach my $key ( keys %$exp ) {
return unless overload::StrVal($got->{$key}) eq overload::StrVal($exp->{$key});
}
return 1;
}
sub compare_test_deep {
my ( $self, $got, $exp ) = @_;
require Test::Deep::NoTest;
Test::Deep::NoTest::eq_deeply($got, $exp);
}
# FIXME Data::Compare too
__PACKAGE__->meta->make_immutable;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Search::GIN::Query::Attributes - Create attributes-based GIN queries
=head1 VERSION
version 0.11
=head1 SYNOPSIS
use Search::GIN::Query::Attributes;
my $query = Search::GIN::Query::Attributes->new(
attributes => {
name => 'Homer',
},
);
=head1 DESCRIPTION
Creates an attributes-based GIN query that can be used to search records in a
storage.
This is a ready-to-use query that uses an object's attributes to search through
the storage.
=head1 METHODS/SUBROUTINES
=head2 new
Creates a new query.
=head1 ATTRIBUTES
=head2 attributes
Attributes of the object you want to find.
my $query = Search::GIN::Query::Attributes->new(
attributes => {
name => 'Homer',
city => 'Springfield',
},
);
=head1 AUTHOR
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2008 by יובל קוג'מן (Yuval Kogman), Infinity Interactive.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|