line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
33428
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
62
|
|
2
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
105
|
|
3
|
|
|
|
|
|
|
package Search::GIN::Query::Class; |
4
|
|
|
|
|
|
|
# ABSTRACT: Create class-based GIN queries |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
968
|
use Moose; |
|
2
|
|
|
|
|
706982
|
|
|
2
|
|
|
|
|
14
|
|
9
|
2
|
|
|
2
|
|
11074
|
use Carp qw(croak); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
119
|
|
10
|
2
|
|
|
2
|
|
1327
|
use namespace::autoclean; |
|
2
|
|
|
|
|
2254
|
|
|
2
|
|
|
|
|
10
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with qw( |
13
|
|
|
|
|
|
|
Search::GIN::Query |
14
|
|
|
|
|
|
|
Search::GIN::Keys::Deep |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has no_check => ( |
18
|
|
|
|
|
|
|
isa => "Bool", |
19
|
|
|
|
|
|
|
is => "rw", |
20
|
|
|
|
|
|
|
default => 0, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has class => ( |
24
|
|
|
|
|
|
|
isa => "ArrayRef | Str", |
25
|
|
|
|
|
|
|
is => "ro", |
26
|
|
|
|
|
|
|
predicate => "has_class", |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has does => ( |
30
|
|
|
|
|
|
|
isa => "ArrayRef | Str", |
31
|
|
|
|
|
|
|
is => "ro", |
32
|
|
|
|
|
|
|
predicate => "has_does", |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has blessed => ( |
36
|
|
|
|
|
|
|
isa => "Str", |
37
|
|
|
|
|
|
|
is => "ro", |
38
|
|
|
|
|
|
|
predicate => "has_blessed", |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub BUILD { |
42
|
3
|
|
|
3
|
0
|
4
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
3
|
0
|
33
|
|
|
95
|
croak "One of 'class', 'does', or 'blessed' is required" |
|
|
|
33
|
|
|
|
|
45
|
|
|
|
|
|
|
unless $self->has_class or $self->has_does or $self->has_blessed; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub extract_values { |
49
|
3
|
|
|
3
|
0
|
3
|
my $self = shift; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return ( |
52
|
3
|
50
|
|
|
|
81
|
method => "all", |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
53
|
|
|
|
|
|
|
values => [ $self->process_keys({ |
54
|
|
|
|
|
|
|
( $self->has_class ? ( class => $self->class ) : () ), |
55
|
|
|
|
|
|
|
( $self->has_does ? ( does => $self->does ) : () ), |
56
|
|
|
|
|
|
|
( $self->has_blessed ? ( blessed => $self->blessed ) : () ), |
57
|
|
|
|
|
|
|
}) ], |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub consistent { |
62
|
9
|
|
|
9
|
0
|
11
|
my ( $self, $index, $object ) = @_; |
63
|
|
|
|
|
|
|
|
64
|
9
|
50
|
|
|
|
245
|
return 1 if $self->no_check; |
65
|
|
|
|
|
|
|
|
66
|
9
|
50
|
|
|
|
274
|
if ( $self->has_blessed ) { |
67
|
0
|
0
|
|
|
|
0
|
return unless ref($object) eq $self->blessed; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
9
|
50
|
|
|
|
241
|
if ( $self->has_class ) { |
71
|
9
|
50
|
|
|
|
221
|
return unless $self->check_object($object, isa => $self->class); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
9
|
50
|
|
|
|
261
|
if ( $self->has_does ) { |
75
|
0
|
0
|
|
|
|
0
|
return unless $self->check_object($object, DOES => $self->does); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
9
|
|
|
|
|
95
|
return 1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub check_object { |
82
|
9
|
|
|
9
|
0
|
10
|
my ( $self, $object, $check, $classes ) = @_; |
83
|
|
|
|
|
|
|
|
84
|
9
|
50
|
|
|
|
23
|
my @classes = ref($classes) ? @$classes : $classes; |
85
|
|
|
|
|
|
|
|
86
|
9
|
|
|
|
|
10
|
foreach my $class ( @classes ) { |
87
|
9
|
50
|
|
|
|
40
|
$object->$check($class) or return; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
9
|
|
|
|
|
24
|
return 1; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=pod |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=encoding UTF-8 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 NAME |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Search::GIN::Query::Class - Create class-based GIN queries |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 VERSION |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
version 0.11 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SYNOPSIS |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
use Search::GIN::Query::Class; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $query = Search::GIN::Query::Class->new( |
116
|
|
|
|
|
|
|
class => 'Person', |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 DESCRIPTION |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Creates a class-based GIN query that can be used to search records in a storage. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This is a ready-to-use query that uses class definitions (specifically C<class>, |
124
|
|
|
|
|
|
|
C<does> and C<blessed>) to search through the storage. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 METHODS/SUBROUTINES |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 new |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Creates a new query. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 class |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
The class of the object you want to find. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $query = Search::GIN::Query::Class->new( |
139
|
|
|
|
|
|
|
class => 'Person', |
140
|
|
|
|
|
|
|
); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 does |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
A role consumed by the object you want to find. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my $query = Search::GIN::Query::Class->new( |
147
|
|
|
|
|
|
|
does => 'TheMonkey', |
148
|
|
|
|
|
|
|
); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 blessed |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
The name of the package that the object is blessed into. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my $query = Search::GIN::Query::Class->new( |
155
|
|
|
|
|
|
|
blessed => 'Person', |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 AUTHOR |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
×××× ×§××'×× (Yuval Kogman) <nothingmuch@woobling.org> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This software is copyright (c) 2008 by ×××× ×§××'×× (Yuval Kogman), Infinity Interactive. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
167
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |