-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dezi.pm
193 lines (122 loc) · 4.44 KB
/
Dezi.pm
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package DBIx::Class::IndexSearch::Dezi;
use Moo;
extends 'DBIx::Class';
use Carp;
use Module::Load;
__PACKAGE__->mk_classdata( map_to => undef );
__PACKAGE__->mk_classdata( query_parameters => {} );
__PACKAGE__->mk_classdata( webservice_classname => undef );
__PACKAGE__->mk_classdata( _index_fields => {} );
__PACKAGE__->mk_classdata( _webservice => undef );
=head1 NAME
DBIx::Class::IndexSearch::Dezi
=head1 VERSION
Version 0.05
=cut
our $VERSION = '0.05';
=head1 SYNOPSIS
package MyApp::Schema::Person;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw[
IndexSearch::Dezi
Core
]);
__PACKAGE__->table('person');
__PACKAGE__->add_columns(
person_id => {
data_type => 'varchar',
size => '36',
},
name => {
data_type => 'varchar',
indexed => 1
},
email => {
data_type => 'varchar',
size=>'128',
indexed => 1
},
);
__PACKAGE__->resultset_class('DBIx::Class::IndexSearch::ResultSet::Dezi');
__PACKAGE__->belongs_to_index('FooClient', { server => 'http://localhost:6000', map_to => 'person_id' });
=head1 SUBROUTINES/METHODS
=head2 belongs_to_index ( $class, $webservice_class, \%parameters )
This sets up the the webservice to use and maps the webservice index
to the DB.
=cut
sub belongs_to_index {
my ( $class, $webservice_classname, $parameters ) = @_;
croak 'Please specify a webservice' if !$webservice_classname;
croak 'Please supply hostname ' if !$parameters->{server};
croak 'Please supply map_to ' if !$parameters->{map_to};
$class->webservice_classname( $webservice_classname );
$class->query_parameters( $parameters || {} );
$class->map_to( $parameters->{map_to} || '' );
}
=head2 index_key_exists ( $class, $key )
Find if the key exists as a registered index field.
=cut
sub index_key_exists {
my( $class, $key ) = @_;
return exists $class->_index_fields->{ $key };
}
=head2 register_column ( $class, $webservice_class, \%parameters )
Override to the register_column method. Add any "indexed" fields we
want to search against Dezi.
=cut
sub register_column {
my ( $class, $column, $info ) = @_;
$class->next::method( $column, $info );
if (exists $info->{ indexed }) {
$class->set_index_field( $column => $info->{ indexed } );
}
}
=head2 set_index_field ( $class, $key, $value )
Setter wrapper to register an indexed field.
=cut
sub set_index_field {
my( $class, $key, $value ) = @_;
$class->_index_fields->{ $key } = $value;
}
=head2 webservice ( $class )
Returns a webservice object.
=cut
sub webservice {
my ( $class ) = @_;
if ( !$class->_webservice && $class->webservice_classname ) {
my $webservice_classname = $class->webservice_classname;
load $webservice_classname;
my $webservice_obj = $webservice_classname->new(server => $class->query_parameters->{server});
$class->_webservice($webservice_obj);
}
return $class->_webservice;
}
=head1 AUTHOR
Logan Bell, C<< <loganbell at gmail.com> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-dbix-class-indexsearch-dezi at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-IndexSearch-Dezi>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc DBIx::Class::IndexSearch::Dezi
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker (report bugs here)
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-IndexSearch-Dezi>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/DBIx-Class-IndexSearch-Dezi>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/DBIx-Class-IndexSearch-Dezi>
=item * Search CPAN
L<http://search.cpan.org/dist/DBIx-Class-IndexSearch-Dezi/>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2011 Logan Bell.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
1; # End of DBIx::Class::IndexSearch::Dezi