| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catalyst::Model::Tarantool; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
41287
|
use 5.014002; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
39
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
35
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
14
|
|
|
|
1
|
|
|
|
|
41
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use base 'Catalyst::Model'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
678
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
53425
|
use MRO::Compat; |
|
|
1
|
|
|
|
|
20815
|
|
|
|
1
|
|
|
|
|
119
|
|
|
10
|
1
|
|
|
1
|
|
12
|
use mro 'c3'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
8
|
|
|
11
|
1
|
|
|
1
|
|
2431
|
use DR::Tarantool::SyncClient; |
|
|
1
|
|
|
|
|
229664
|
|
|
|
1
|
|
|
|
|
34
|
|
|
12
|
1
|
|
|
1
|
|
758
|
use Catalyst::Exception; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Data::Dumper; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw/_handler app/ ); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
|
|
|
|
|
|
my ( $class, $c, $config ) = @_; |
|
21
|
|
|
|
|
|
|
my $self = shift->next::method( @_ ); |
|
22
|
|
|
|
|
|
|
$self->{host} ||= $config->{host}; |
|
23
|
|
|
|
|
|
|
$self->{port} ||= $config->{port}; |
|
24
|
|
|
|
|
|
|
$self->{spaces} ||= $config->{spaces}; |
|
25
|
|
|
|
|
|
|
$self->{reconnect_period} ||= $config->{reconnect_period}; |
|
26
|
|
|
|
|
|
|
$self->{reconnect_always} ||= $config->{reconnect_always}; |
|
27
|
|
|
|
|
|
|
$self->app($c); |
|
28
|
|
|
|
|
|
|
return $self; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub handler{ |
|
32
|
|
|
|
|
|
|
my ($self) = @_; |
|
33
|
|
|
|
|
|
|
my $connection = $self->_handler; |
|
34
|
|
|
|
|
|
|
unless ( $connection ) { |
|
35
|
|
|
|
|
|
|
eval { |
|
36
|
|
|
|
|
|
|
my $connection = DR::Tarantool::SyncClient->connect( |
|
37
|
|
|
|
|
|
|
host => $self->{host}, |
|
38
|
|
|
|
|
|
|
port => $self->{port}, |
|
39
|
|
|
|
|
|
|
spaces => $self->{spaces}, |
|
40
|
|
|
|
|
|
|
reconnect_period => 0.5, |
|
41
|
|
|
|
|
|
|
reconnect_always => 1 |
|
42
|
|
|
|
|
|
|
); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$self->_handler( $connection ); |
|
45
|
|
|
|
|
|
|
}; |
|
46
|
|
|
|
|
|
|
if ($@) { |
|
47
|
|
|
|
|
|
|
Catalyst::Exception->throw( qq/Couldn't connect to the Tarantool via DR::Tarantool - "$@"/ ); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
return $self->_handler; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Preloaded methods go here. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
|
56
|
|
|
|
|
|
|
__END__ |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 NAME |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Catalyst::Model::Tarantool - L<DR::Tarantool> interface |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head4 MyApp.pm |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
package MyApp; |
|
67
|
|
|
|
|
|
|
... |
|
68
|
|
|
|
|
|
|
__PACKAGE__->config( |
|
69
|
|
|
|
|
|
|
'Tarantool' => { |
|
70
|
|
|
|
|
|
|
host => '128.0.0.1', |
|
71
|
|
|
|
|
|
|
port => '33013' |
|
72
|
|
|
|
|
|
|
spaces => { |
|
73
|
|
|
|
|
|
|
0 => { |
|
74
|
|
|
|
|
|
|
name => 'spane_name', # space name |
|
75
|
|
|
|
|
|
|
default_type => 'STR', # undescribed fields |
|
76
|
|
|
|
|
|
|
fields => [ |
|
77
|
|
|
|
|
|
|
qw( field_1 field_2 ), |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
|
|
|
|
|
|
name => 'firld_3', |
|
80
|
|
|
|
|
|
|
type => 'NUM' |
|
81
|
|
|
|
|
|
|
}, |
|
82
|
|
|
|
|
|
|
], |
|
83
|
|
|
|
|
|
|
indexes => { |
|
84
|
|
|
|
|
|
|
0 => 'field_1', |
|
85
|
|
|
|
|
|
|
1 => [ qw( field_1 field_2 ) ], |
|
86
|
|
|
|
|
|
|
2 => { |
|
87
|
|
|
|
|
|
|
name => 'me_idx_1', |
|
88
|
|
|
|
|
|
|
fields => 'field_1' |
|
89
|
|
|
|
|
|
|
}, |
|
90
|
|
|
|
|
|
|
3 => { |
|
91
|
|
|
|
|
|
|
name => 'my_idx_2', |
|
92
|
|
|
|
|
|
|
fields => [ 'field_1', 'field_3' ] |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
}, |
|
96
|
|
|
|
|
|
|
1 => { |
|
97
|
|
|
|
|
|
|
... |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head4 Controller |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
package MyApp::Controller::Root |
|
106
|
|
|
|
|
|
|
... |
|
107
|
|
|
|
|
|
|
sub index :Path :Args(0) { |
|
108
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
|
109
|
|
|
|
|
|
|
my $tnt = $c->model('TNT')->handler; |
|
110
|
|
|
|
|
|
|
my $tuple = $tnt->select(space_name => $key); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Tarantool interface for Catalyst based application |
|
116
|
|
|
|
|
|
|
L<DR::Tarantool>. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Alexey Orlov, E<lt>aorlov@cpan.orgE<gt> |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Copyright (C) 2013 by Alexey Orlov |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
127
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.14.2 or, |
|
128
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |