| 1 | package Dancer::Plugin::ElasticSearch; | ||
| 2 | |||
| 3 | # ABSTRACT: An ElasticSearch wrapper for Dancer | ||
| 4 | |||
| 5 | use Dancer qw(:syntax); | ||
| 6 | use Dancer::Plugin; | ||
| 7 | |||
| 8 | use ElasticSearch; | ||
| 9 | |||
| 10 | ### TODO : connection pooling | ||
| 11 | my $Connection; | ||
| 12 | |||
| 13 | register elsearch => sub { | ||
| 14 | return $Connection || _create_connection(); | ||
| 15 | }; | ||
| 16 | |||
| 17 | sub _create_connection { | ||
| 18 | my $settings = plugin_setting; | ||
| 19 | my $cxn = ElasticSearch->new(%$settings) | ||
| 20 | or die q(Error creating ElasticSearch connection); | ||
| 21 | return $Connection = $cxn; | ||
| 22 | } | ||
| 23 | |||
| 24 | register_plugin; | ||
| 25 | |||
| 26 | true; | ||
| 27 | |||
| 28 | __END__ |