| 1 | use utf8; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | package DR::Tnt; | ||
| 6 | use base qw(Exporter); | ||
| 7 | our $VERSION = '0.22'; | ||
| 8 | our @EXPORT = qw(tarantool); | ||
| 9 | use List::MoreUtils 'any'; | ||
| 10 | |||
| 11 | use Carp; | ||
| 12 | $Carp::Internal{ (__PACKAGE__) }++; | ||
| 13 | |||
| 14 | sub tarantool { | ||
| 15 | my (%opts) = @_; | ||
| 16 | |||
| 17 | my $driver = delete($opts{driver}) || 'sync'; | ||
| 18 | |||
| 19 | unless (any { $driver eq $_ } 'sync', 'ae', 'async', 'coro') { | ||
| 20 | goto usage; | ||
| 21 | } | ||
| 22 | |||
| 23 | |||
| 24 | goto $driver; | ||
| 25 | sync: | ||
| 26 | require DR::Tnt::Client::Sync; | ||
| 27 | return DR::Tnt::Client::Sync->new(%opts); | ||
| 28 | |||
| 29 | ae: | ||
| 30 | async: | ||
| 31 | require DR::Tnt::Client::AE; | ||
| 32 | return DR::Tnt::Client::AE->new(%opts); | ||
| 33 | |||
| 34 | coro: | ||
| 35 | require DR::Tnt::Client::Coro; | ||
| 36 | return DR::Tnt::Client::Coro->new(%opts); | ||
| 37 | |||
| 38 | |||
| 39 | usage: | ||
| 40 | croak "Too few information about tarantool connection"; | ||
| 41 | } | ||
| 42 | |||
| 43 | 1; | ||
| 44 | |||
| 45 | __END__ |