|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
62697
 | 
 use utf8;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
23
 | 
    | 
| 
2
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
143
 | 
 use strict;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
88
 | 
    | 
| 
3
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
10
 | 
 use warnings;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
116
 | 
    | 
| 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package DR::Tarantool::Spaces;  | 
| 
6
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
13
 | 
 use Carp;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2681
 | 
    | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 $Carp::Internal{ (__PACKAGE__) }++;  | 
| 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 my $LE = $] > 5.01 ? '<' : '';  | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 NAME  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 DR::Tarantool::Spaces - Tarantool schema description   | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 SYNOPSIS  | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     use DR::Tarantool::Spaces;  | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $s = new DR::Tarantool::Spaces({  | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             1   => {  | 
| 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 name            => 'users',         # space name  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 default_type    => 'STR',           # undescribed fields  | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 fields  => [  | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     qw(login password role),  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     {  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         name    => 'counter',  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         type    => 'NUM'  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     },  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     {  | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         name    => 'something',  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         type    => 'UTF8STR',  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     },  | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     {  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         name    => 'opts',  | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         type    => 'JSON',  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     }  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 ],  | 
| 
37
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 indexes => {  | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     0   => 'login',  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     1   => [ qw(login password) ],  | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     2   => {  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         name    => 'my_idx',  | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         fields  => 'login',  | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     },  | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     3   => {  | 
| 
45
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         name    => 'my_idx2',  | 
| 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         fields  => [ 'counter', 'something' ]  | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     }  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 }  | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             },  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             0 => {  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 ...  | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     });  | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $f = $s->pack_field('users', 'counter', 10);  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $f = $s->pack_field('users', 3, 10);             # the same  | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $f = $s->pack_field(1, 3, 10);                   # the same  | 
| 
59
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
60
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $ts = $s->pack_keys([1,2,3] => 'my_idx');  | 
| 
61
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $t = $s->pack_primary_key([1,2,3]);  | 
| 
62
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
64
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 DESCRIPTION  | 
| 
65
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
66
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 The package describes all spaces used in an application.  | 
| 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 It supports the following field types:  | 
| 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
69
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =over  | 
| 
70
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
71
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item NUM, NUM64, STR  | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 The standard L types.  | 
| 
74
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item UTF8STR  | 
| 
76
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
77
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 The same as B, but the string is utf8-decoded   | 
| 
78
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 after it's received from the server.  | 
| 
79
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
80
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item INT & INT64  | 
| 
81
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
82
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 The same as B and B, but contain signed values.  | 
| 
83
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
84
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =item JSON  | 
| 
85
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
86
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 The field is encoded with L when putting  | 
| 
87
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 into a database, and decoded after is received back   | 
| 
88
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 from the server.  | 
| 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
90
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =back  | 
| 
91
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 METHODS  | 
| 
93
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
94
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 new  | 
| 
95
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
96
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $spaces = DR::Tarantool::Spaces->new( $spaces );  | 
| 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
98
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
99
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
100
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub new {  | 
| 
101
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
  
1
  
 | 
560
 | 
     my ($class, $spaces, %opts) = @_;  | 
| 
102
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
103
 | 
5
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
24
 | 
     $opts{family} ||= 1;  | 
| 
104
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
105
 | 
5
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
11
 | 
     $spaces = {} unless defined $spaces;  | 
| 
106
 | 
5
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
196
 | 
     croak 'spaces must be a HASHREF' unless 'HASH' eq ref $spaces;  | 
| 
107
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
108
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     my (%spaces, %fast);  | 
| 
109
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
     for (keys %$spaces) {  | 
| 
110
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
19
 | 
         my $s = new DR::Tarantool::Space($_ => $spaces->{ $_ }, %opts);  | 
| 
111
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
         $spaces{ $s->name } = $s;  | 
| 
112
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
         $fast{ $_ } = $s->name;  | 
| 
113
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
114
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
115
 | 
3
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
36
 | 
     return bless {  | 
| 
116
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         spaces  => \%spaces,  | 
| 
117
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         fast    => \%fast,  | 
| 
118
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         family  => $opts{family},  | 
| 
119
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     } => ref($class) || $class;  | 
| 
120
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
121
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
122
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
123
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub family {  | 
| 
124
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
  
0
  
 | 
11
 | 
     my ($self, $family) = @_;  | 
| 
125
 | 
3
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
13
 | 
     return $self->{family} if @_ == 1;  | 
| 
126
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
     $self->{family} = $family;  | 
| 
127
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
     $_->family($family) for values %{ $self->{spaces} };  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
    | 
| 
128
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
     return $self->{family};  | 
| 
129
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
130
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
131
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
132
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 space  | 
| 
133
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
134
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Return space object by number or name.  | 
| 
135
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
136
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $space = $spaces->space('name');  | 
| 
137
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $space = $spaces->space(0);  | 
| 
138
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
139
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
140
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
141
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub space {  | 
| 
142
 | 
94
 | 
 
 | 
 
 | 
  
94
  
 | 
  
1
  
 | 
20348
 | 
     my ($self, $space) = @_;  | 
| 
143
 | 
94
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
255
 | 
     croak 'space name or number is not defined' unless defined $space;  | 
| 
144
 | 
93
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
249
 | 
     if ($space =~ /^\d+$/) {  | 
| 
145
 | 
6
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
18
 | 
         croak "space '$space' is not defined"  | 
| 
146
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             unless exists $self->{fast}{$space};  | 
| 
147
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
23
 | 
         return $self->{spaces}{ $self->{fast}{$space} };  | 
| 
148
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
149
 | 
87
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
192
 | 
     croak "space '$space' is not defined"  | 
| 
150
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         unless exists $self->{spaces}{$space};  | 
| 
151
 | 
87
 | 
 
 | 
 
 | 
 
 | 
 
 | 
314
 | 
     return $self->{spaces}{$space};  | 
| 
152
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
153
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
154
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
155
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 space_number  | 
| 
156
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
157
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Return space number by its name.  | 
| 
158
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
159
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
160
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
161
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub space_number {  | 
| 
162
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
  
1
  
 | 
536
 | 
     my ($self, $space) = @_;  | 
| 
163
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
     return $self->space($space)->number;  | 
| 
164
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
165
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
166
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
167
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 pack_field  | 
| 
168
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
169
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Packs one field into a format suitable for making a database request:  | 
| 
170
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
171
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $field = $spaces->pack_field('space', 'field', $data);  | 
| 
172
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
173
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
174
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
175
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub pack_field {  | 
| 
176
 | 
23
 | 
 
 | 
 
 | 
  
23
  
 | 
  
1
  
 | 
8531
 | 
     my ($self, $space, $field, $value) = @_;  | 
| 
177
 | 
23
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
57
 | 
     croak q{Usage: $spaces->pack_field('space', 'field', $value)}  | 
| 
178
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         unless @_ == 4;  | 
| 
179
 | 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
40
 | 
     return $self->space($space)->pack_field($field => $value);  | 
| 
180
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
181
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
182
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
183
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 unpack_field  | 
| 
184
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
185
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Unpack one field after getting it from the server:  | 
| 
186
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
187
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $field = $spaces->unpack_field('space', 'field', $data);  | 
| 
188
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
189
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
190
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
191
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub unpack_field {  | 
| 
192
 | 
19
 | 
 
 | 
 
 | 
  
19
  
 | 
  
1
  
 | 
5770
 | 
     my ($self, $space, $field, $value) = @_;  | 
| 
193
 | 
19
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
53
 | 
     croak q{Usage: $spaces->unpack_field('space', 'field', $value)}  | 
| 
194
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         unless @_ == 4;  | 
| 
195
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
196
 | 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
29
 | 
     return $self->space($space)->unpack_field($field => $value);  | 
| 
197
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
198
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
199
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
200
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 pack_tuple  | 
| 
201
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
202
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Pack a tuple before making database request.  | 
| 
203
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
204
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $t = $spaces->pack_tuple('space', [ 1, 2, 3 ]);  | 
| 
205
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
206
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
207
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
208
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub pack_tuple {  | 
| 
209
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
  
1
  
 | 
292
 | 
     my ($self, $space, $tuple) = @_;  | 
| 
210
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     croak q{Usage: $spaces->pack_tuple('space', $tuple)} unless @_ == 3;  | 
| 
211
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
     return $self->space($space)->pack_tuple( $tuple );  | 
| 
212
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
213
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
214
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
215
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 unpack_tuple  | 
| 
216
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
217
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Unpack a tuple after getting it from the database:   | 
| 
218
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
219
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $t = $spaces->unpack_tuple('space', \@fields);  | 
| 
220
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
221
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
222
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
223
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub unpack_tuple {  | 
| 
224
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
  
1
  
 | 
283
 | 
     my ($self, $space, $tuple) = @_;  | 
| 
225
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     croak q{Usage: $spaces->unpack_tuple('space', $tuple)} unless @_ == 3;  | 
| 
226
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
     return $self->space($space)->unpack_tuple( $tuple );  | 
| 
227
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
228
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
229
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package DR::Tarantool::Space;  | 
| 
230
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
19
 | 
 use Carp;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
230
 | 
    | 
| 
231
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 $Carp::Internal{ (__PACKAGE__) }++;  | 
| 
232
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
2356
 | 
 use JSON::XS ();  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
19921
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
77
 | 
    | 
| 
233
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
19
 | 
 use Digest::MD5 ();  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2899
 | 
    | 
| 
234
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
235
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
236
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 SPACES methods  | 
| 
237
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
238
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 new  | 
| 
239
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
240
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 constructor  | 
| 
241
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
242
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     use DR::Tarantool::Spaces;  | 
| 
243
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $space = DR::Tarantool::Space->new($no, $space);  | 
| 
244
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
245
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
246
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
247
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub new {  | 
| 
248
 | 
4
 | 
 
 | 
 
 | 
  
4
  
 | 
 
 | 
9
 | 
     my ($class, $no, $space, %opts) = @_;  | 
| 
249
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
250
 | 
4
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
10
 | 
     $opts{family} ||= 1;  | 
| 
251
 | 
4
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
131
 | 
     croak 'space number must conform the regexp qr{^\d+}'  | 
| 
252
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         unless defined $no and $no =~ /^\d+$/;  | 
| 
253
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
11
 | 
     croak "'fields' not defined in space hash"  | 
| 
254
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         unless 'ARRAY' eq ref $space->{fields};  | 
| 
255
 | 
3
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
18
 | 
     croak "wrong 'indexes' hash"  | 
| 
256
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         if !$space->{indexes} or 'HASH' ne ref $space->{indexes};  | 
| 
257
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
258
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     my $name = $space->{name};  | 
| 
259
 | 
3
 | 
  
  0
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
72
 | 
     croak 'wrong space name: ' . (defined($name) ? $name : 'undef')  | 
| 
 
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
260
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         unless $name and $name =~ /^[a-z_]\w*$/i;  | 
| 
261
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
262
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
263
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
     my $fqr = qr{^(?:STR|NUM|NUM64|INT|INT64|UTF8STR|JSON|MONEY|BIGMONEY)$};  | 
| 
264
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
265
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     my (@fields, %fast, $default_type);  | 
| 
266
 | 
3
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
10
 | 
     $default_type = $space->{default_type} || 'STR';  | 
| 
267
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
19
 | 
     croak "wrong 'default_type'" unless $default_type =~ $fqr;  | 
| 
268
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
269
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     for (my $no = 0; $no < @{ $space->{fields} }; $no++) {  | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
36
 | 
    | 
| 
270
 | 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
19
 | 
         my $f = $space->{ fields }[ $no ];  | 
| 
271
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
272
 | 
15
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
34
 | 
         if (ref $f eq 'HASH') {  | 
| 
 
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
273
 | 
9
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
34
 | 
             push @fields => {  | 
| 
274
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 name    => $f->{name} || "f$no",  | 
| 
275
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 idx     => $no,  | 
| 
276
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 type    => $f->{type}  | 
| 
277
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             };  | 
| 
278
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         } elsif(ref $f) {  | 
| 
279
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             croak 'wrong field name or description';  | 
| 
280
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         } else {  | 
| 
281
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
22
 | 
             push @fields => {  | 
| 
282
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 name    => $f,  | 
| 
283
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 idx     => $no,  | 
| 
284
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 type    => $default_type,  | 
| 
285
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
286
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
287
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
288
 | 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12
 | 
         my $s = $fields[ -1 ];  | 
| 
289
 | 
15
 | 
  
  0
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
98
 | 
         croak 'unknown field type: ' .  | 
| 
 
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
290
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             (defined($s->{type}) ? $s->{type} : 'undef')  | 
| 
291
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 unless $s->{type} and $s->{type} =~ $fqr;  | 
| 
292
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
293
 | 
15
 | 
  
  0
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
72
 | 
         croak 'wrong field name: ' .  | 
| 
 
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
294
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             (defined($s->{name}) ? $s->{name} : 'undef')  | 
| 
295
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 unless $s->{name} and $s->{name} =~ /^[a-z_]\w*$/i;  | 
| 
296
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
297
 | 
15
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
44
 | 
         croak "Duplicate field name: $s->{name}" if exists $fast{ $s->{name} };  | 
| 
298
 | 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
33
 | 
         $fast{ $s->{name} } = $no;  | 
| 
299
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
300
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
301
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     my %indexes;  | 
| 
302
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
7
 | 
     if ($space->{indexes}) {  | 
| 
303
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
         for my $no (keys %{ $space->{indexes} }) {  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
    | 
| 
304
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
             my $l = $space->{indexes}{ $no };  | 
| 
305
 | 
6
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
18
 | 
             croak "wrong index number: $no" unless $no =~ /^\d+$/;  | 
| 
306
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
307
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
             my ($name, $fields);  | 
| 
308
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
309
 | 
6
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
15
 | 
             if ('ARRAY' eq ref $l) {  | 
| 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
310
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
                 $name = "i$no";  | 
| 
311
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
                 $fields = $l;  | 
| 
312
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             } elsif ('HASH' eq ref $l) {  | 
| 
313
 | 
1
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
4
 | 
                 $name = $l->{name} || "i$no";  | 
| 
314
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
                 $fields =  | 
| 
315
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
3
 | 
                     [ ref($l->{fields}) ? @{ $l->{fields} } : $l->{fields} ];  | 
| 
316
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             } else {  | 
| 
317
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
                 $name = "i$no";  | 
| 
318
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
                 $fields = [ $l ];  | 
| 
319
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
320
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
321
 | 
6
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
18
 | 
             croak "wrong index name: $name" unless $name =~ /^[a-z_]\w*$/i;  | 
| 
322
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
323
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
             for (@$fields) {  | 
| 
324
 | 
10
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
31
 | 
                 croak "field '$_' is presend in index but isn't in fields"  | 
| 
325
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     unless exists $fast{ $_ };  | 
| 
326
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
327
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
328
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
23
 | 
             $indexes{ $name } = {  | 
| 
329
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 no      => $no,  | 
| 
330
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 name    => $name,  | 
| 
331
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 fields  => $fields  | 
| 
332
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             };  | 
| 
333
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
334
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
335
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
336
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
337
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
47
 | 
     my $tuple_class = 'DR::Tarantool::Tuple::Instance' .  | 
| 
338
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         Digest::MD5::md5_hex( join "\0", sort keys %fast );  | 
| 
339
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
340
 | 
3
 | 
 
 | 
  
 33
  
 | 
 
 | 
 
 | 
51
 | 
     bless {  | 
| 
341
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         fields          => \@fields,  | 
| 
342
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         fast            => \%fast,  | 
| 
343
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         name            => $name,  | 
| 
344
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         number          => $no,  | 
| 
345
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         default_type    => $default_type,  | 
| 
346
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         indexes         => \%indexes,  | 
| 
347
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         tuple_class     => $tuple_class,  | 
| 
348
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         family          => $opts{family},  | 
| 
349
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     } => ref($class) || $class;  | 
| 
350
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
351
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
352
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
353
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
354
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub family {  | 
| 
355
 | 
21
 | 
 
 | 
 
 | 
  
21
  
 | 
 
 | 
28
 | 
     my ($self, $family) = @_;  | 
| 
356
 | 
21
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
88
 | 
     return $self->{family} if @_ == 1;  | 
| 
357
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
     return $self->{family} = $family;  | 
| 
358
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
359
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
360
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
361
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 tuple_class  | 
| 
362
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
363
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Create (or return) a class to hold tuple data.  | 
| 
364
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 The class is a descendant of L. Returns a unique class  | 
| 
365
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 (package) name. If a package with such name is already exists, the method  | 
| 
366
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 doesn't recreate it.  | 
| 
367
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
368
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
369
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
370
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub tuple_class {  | 
| 
371
 | 
11
 | 
 
 | 
 
 | 
  
11
  
 | 
 
 | 
19
 | 
     my ($self) = @_;  | 
| 
372
 | 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
20
 | 
     my $class = $self->{tuple_class};  | 
| 
373
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
374
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
375
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
20
 | 
     no strict 'refs';  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7454
 | 
    | 
| 
376
 | 
11
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
15
 | 
     return $class if ${ $class . '::CREATED' };  | 
| 
 
 | 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
85
 | 
    | 
| 
377
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
378
 | 
3
 | 
  
 50
  
 | 
 
 | 
  
2
  
 | 
 
 | 
180
 | 
     die unless eval "package $class; use base 'DR::Tarantool::Tuple'; 1";  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
11
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1040
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
62
 | 
    | 
| 
379
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
380
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
36
 | 
     for my $fname (keys %{ $self->{fast} }) {  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
15
 | 
    | 
| 
381
 | 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
24
 | 
         my $fnumber = $self->{fast}{$fname};  | 
| 
382
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
383
 | 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
726
 | 
         *{ $class . '::' . $fname } = eval "sub { \$_[0]->raw($fnumber) }";  | 
| 
 
 | 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
88
 | 
    | 
| 
384
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
385
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
386
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
15
 | 
     ${ $class . '::CREATED' } = time;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
    | 
| 
387
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
388
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
     return $class;  | 
| 
389
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
390
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
391
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
392
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 name  | 
| 
393
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
394
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Get a space name.  | 
| 
395
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
396
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
397
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
398
 | 
6
 | 
 
 | 
 
 | 
  
6
  
 | 
 
 | 
32
 | 
 sub name { $_[0]{name} }  | 
| 
399
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
400
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
401
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 number  | 
| 
402
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
403
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Get a space number.  | 
| 
404
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
405
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
406
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
407
 | 
3
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
12
 | 
 sub number { $_[0]{number} }  | 
| 
408
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
409
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _field {  | 
| 
410
 | 
105
 | 
 
 | 
 
 | 
  
105
  
 | 
 
 | 
94
 | 
     my ($self, $field) = @_;  | 
| 
411
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
412
 | 
112
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
566
 | 
     croak 'field name or number is not defined' unless defined $field;  | 
| 
413
 | 
106
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
226
 | 
     if ($field =~ /^\d+$/) {  | 
| 
414
 | 
24
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
35
 | 
         return $self->{fields}[ $field ] if $field < @{ $self->{fields} };  | 
| 
 
 | 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
62
 | 
    | 
| 
415
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         return undef;  | 
| 
416
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
417
 | 
85
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
152
 | 
     croak "field with name '$field' is not defined in this space"  | 
| 
418
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         unless exists $self->{fast}{$field};  | 
| 
419
 | 
85
 | 
 
 | 
 
 | 
 
 | 
 
 | 
127
 | 
     return $self->{fields}[ $self->{fast}{$field} ];  | 
| 
420
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
421
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
422
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
423
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 field_number  | 
| 
424
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
425
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Return field index by field name.  | 
| 
426
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
427
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
428
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
429
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub field_number {  | 
| 
430
 | 
4
 | 
 
 | 
 
 | 
  
4
  
 | 
 
 | 
5
 | 
     my ($self, $field) = @_;  | 
| 
431
 | 
4
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
8
 | 
     croak 'field name or number is not defined' unless defined $field;  | 
| 
432
 | 
4
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
20
 | 
     return $self->{fast}{$field} if exists $self->{fast}{$field};  | 
| 
433
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
89
 | 
     croak "Can't find field '$field' in this space";  | 
| 
434
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
435
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
436
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
437
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 tail_index  | 
| 
438
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
439
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Return index of the first element that is not described in the space.  | 
| 
440
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
441
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
442
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
443
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub tail_index {  | 
| 
444
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
6
 | 
     my ($self) = @_;  | 
| 
445
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     return scalar @{ $self->{fields} };  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
21
 | 
    | 
| 
446
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
447
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
448
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
449
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 pack_field  | 
| 
450
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
451
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Pack a field before making a database request.  | 
| 
452
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
453
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
454
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
455
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub pack_field {  | 
| 
456
 | 
52
 | 
 
 | 
 
 | 
  
52
  
 | 
 
 | 
64
 | 
     my ($self, $field, $value) = @_;  | 
| 
457
 | 
52
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
73
 | 
     croak q{Usage: $space->pack_field('field', $value)}  | 
| 
458
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         unless @_ == 3;  | 
| 
459
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
460
 | 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
67
 | 
     my $f = $self->_field($field);  | 
| 
461
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
462
 | 
52
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
113
 | 
     my $type = $f ? $f->{type} : $self->{default_type};  | 
| 
463
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
464
 | 
52
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
83
 | 
     if ($type eq 'JSON') {  | 
| 
465
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
         my $v = eval { JSON::XS->new->allow_nonref->utf8->encode( $value ) };  | 
| 
 
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
74
 | 
    | 
| 
466
 | 
8
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
25
 | 
         croak "Can't pack json: $@" if $@;  | 
| 
467
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
24
 | 
         return $v;  | 
| 
468
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
469
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
470
 | 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
35
 | 
     my $v = $value;  | 
| 
471
 | 
44
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
90
 | 
     utf8::encode( $v ) if utf8::is_utf8( $v );  | 
| 
472
 | 
44
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
168
 | 
     return $v if $type eq 'STR' or $type eq 'UTF8STR';  | 
| 
473
 | 
37
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
179
 | 
     return pack "L$LE" => $v if $type eq 'NUM';  | 
| 
474
 | 
8
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
20
 | 
     return pack "l$LE" => $v if $type eq 'INT';  | 
| 
475
 | 
7
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
14
 | 
     return pack "Q$LE" => $v if $type eq 'NUM64';  | 
| 
476
 | 
7
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
10
 | 
     return pack "q$LE" => $v if $type eq 'INT64';  | 
| 
477
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
478
 | 
7
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
16
 | 
     if ($type eq 'MONEY' or $type eq 'BIGMONEY') {  | 
| 
479
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16
 | 
         my ($r, $k) = split /\./, $v;  | 
| 
480
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
         for ($k) {  | 
| 
481
 | 
7
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
13
 | 
             $_ = '.00' unless defined $_;  | 
| 
482
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
14
 | 
             s/^\.//;  | 
| 
483
 | 
7
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
12
 | 
             $_ .= '0' if length $_ < 2;  | 
| 
484
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
14
 | 
             $_ = substr $_, 0, 2;  | 
| 
485
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
486
 | 
7
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
15
 | 
         $r ||= 0;  | 
| 
487
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
488
 | 
7
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
13
 | 
         if ($r < 0) {  | 
| 
489
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
             $v = $r * 100 - $k;  | 
| 
490
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         } else {  | 
| 
491
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
             $v = $r * 100 + $k;  | 
| 
492
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
493
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
494
 | 
7
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
41
 | 
         return pack "l$LE", $v if $type eq 'MONEY';  | 
| 
495
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         return pack "q$LE", $v;  | 
| 
496
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
497
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
498
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
499
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     croak 'Unknown field type:' . $type;  | 
| 
500
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
501
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
502
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
503
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 unpack_field  | 
| 
504
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
505
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Unpack a single field in a server response.  | 
| 
506
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
507
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
508
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
509
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub unpack_field {  | 
| 
510
 | 
27
 | 
 
 | 
 
 | 
  
27
  
 | 
 
 | 
34
 | 
     my ($self, $field, $value) = @_;  | 
| 
511
 | 
27
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
46
 | 
     croak q{Usage: $space->pack_field('field', $value)}  | 
| 
512
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         unless @_ == 3;  | 
| 
513
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
514
 | 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
42
 | 
     my $f = $self->_field($field);  | 
| 
515
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
516
 | 
27
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
56
 | 
     my $type = $f ? $f->{type} : $self->{default_type};  | 
| 
517
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
518
 | 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
26
 | 
     my $v = $value;  | 
| 
519
 | 
27
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
64
 | 
     utf8::encode( $v ) if utf8::is_utf8( $v );  | 
| 
520
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
521
 | 
27
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
41
 | 
     if ($type eq 'JSON') {  | 
| 
522
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
57
 | 
         $v = JSON::XS->new->allow_nonref->utf8->decode( $v );  | 
| 
523
 | 
8
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
25
 | 
         croak "Can't unpack json: $@" if $@;  | 
| 
524
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
27
 | 
         return $v;  | 
| 
525
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
526
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
527
 | 
19
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
82
 | 
     $v = unpack "L$LE" => $v  if $type eq 'NUM';  | 
| 
528
 | 
19
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
35
 | 
     $v = unpack "l$LE" => $v  if $type eq 'INT';  | 
| 
529
 | 
19
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
36
 | 
     $v = unpack "Q$LE" => $v  if $type eq 'NUM64';  | 
| 
530
 | 
19
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
27
 | 
     $v = unpack "q$LE" => $v  if $type eq 'INT64';  | 
| 
531
 | 
19
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
31
 | 
     utf8::decode( $v )      if $type eq 'UTF8STR';  | 
| 
532
 | 
19
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
61
 | 
     if ($type eq 'MONEY' or $type eq 'BIGMONEY') {  | 
| 
533
 | 
4
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
14
 | 
         $v = unpack "l$LE" => $v if $type eq 'MONEY';  | 
| 
534
 | 
4
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
10
 | 
         $v = unpack "q$LE" => $v if $type eq 'BIGMONEY';  | 
| 
535
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
         my $s = '';  | 
| 
536
 | 
4
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
8
 | 
         if ($v < 0) {  | 
| 
537
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
             $v = -$v;  | 
| 
538
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
             $s = '-';  | 
| 
539
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
540
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
         my $k = $v % 100;  | 
| 
541
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
         my $r = ($v - $k) / 100;  | 
| 
542
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
15
 | 
         $v = sprintf '%s%d.%02d', $s, $r, $k;  | 
| 
543
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
544
 | 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
48
 | 
     return $v;  | 
| 
545
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
546
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
547
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
548
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 pack_tuple  | 
| 
549
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
550
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Pack a tuple to the binary protocol format:  | 
| 
551
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
552
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
553
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
554
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub pack_tuple {  | 
| 
555
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
2
 | 
     my ($self, $tuple) = @_;  | 
| 
556
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     croak 'tuple must be ARRAYREF' unless 'ARRAY' eq ref $tuple;  | 
| 
557
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1
 | 
     my @res;  | 
| 
558
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     if ($self->family == 1) {  | 
| 
559
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
         for (my $i = 0; $i < @$tuple; $i++) {  | 
| 
560
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
             push @res => $self->pack_field($i, $tuple->[ $i ]);  | 
| 
561
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
562
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     } else {  | 
| 
563
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         @res = @$tuple;  | 
| 
564
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
565
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     return \@res;  | 
| 
566
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
567
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
568
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
569
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 unpack_tuple  | 
| 
570
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
571
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Unpack a tuple in a server response.  | 
| 
572
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
573
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
574
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
575
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub unpack_tuple {  | 
| 
576
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
4
 | 
     my ($self, $tuple) = @_;  | 
| 
577
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
9
 | 
     croak 'tuple must be ARRAYREF' unless 'ARRAY' eq ref $tuple;  | 
| 
578
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     my @res;  | 
| 
579
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
7
 | 
     if ($self->family == 1) {  | 
| 
580
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
         for (my $i = 0; $i < @$tuple; $i++) {  | 
| 
581
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
18
 | 
             push @res => $self->unpack_field($i, $tuple->[ $i ]);  | 
| 
582
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
583
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     } else {  | 
| 
584
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         @res = @$tuple;  | 
| 
585
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
586
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
     return \@res;  | 
| 
587
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
588
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
589
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
590
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _index {  | 
| 
591
 | 
16
 | 
 
 | 
 
 | 
  
16
  
 | 
 
 | 
19
 | 
     my ($self, $index) = @_;  | 
| 
592
 | 
16
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
54
 | 
     if ($index =~ /^\d+$/) {  | 
| 
593
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
         for (values %{ $self->{indexes} }) {  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16
 | 
    | 
| 
594
 | 
8
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
31
 | 
             return $_ if $_->{no} == $index;  | 
| 
595
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
596
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         croak "index $index is undefined";  | 
| 
597
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
598
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
599
 | 
11
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
41
 | 
     return $self->{indexes}{$index} if exists $self->{indexes}{$index};  | 
| 
600
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
76
 | 
     croak "index `$index' is undefined";  | 
| 
601
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
602
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
603
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
604
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 index_number  | 
| 
605
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
606
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 returns index number by its name.  | 
| 
607
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
608
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
609
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
610
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub index_number {  | 
| 
611
 | 
4
 | 
 
 | 
 
 | 
  
4
  
 | 
 
 | 
5
 | 
     my ($self, $idx) = @_;  | 
| 
612
 | 
4
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
101
 | 
     croak "index name is undefined" unless defined $idx;  | 
| 
613
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     return $self->_index( $idx )->{no};  | 
| 
614
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
615
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
616
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
617
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 index_name  | 
| 
618
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
619
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 returns index name by its number.  | 
| 
620
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
621
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
622
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
623
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub index_name {  | 
| 
624
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
3
 | 
     my ($self, $idx) = @_;  | 
| 
625
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     croak "index number is undefined" unless defined $idx;  | 
| 
626
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     return $self->_index( $idx )->{name};  | 
| 
627
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
628
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
629
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
630
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub pack_keys {  | 
| 
631
 | 
11
 | 
 
 | 
 
 | 
  
11
  
 | 
 
 | 
13
 | 
     my ($self, $keys, $idx, $disable_warn) = @_;  | 
| 
632
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
633
 | 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
21
 | 
     $idx = $self->_index($idx);  | 
| 
634
 | 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
     my $ksize = @{ $idx->{fields} };  | 
| 
 
 | 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
17
 | 
    | 
| 
635
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
636
 | 
11
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
27
 | 
     $keys = [[ $keys ]] unless 'ARRAY' eq ref $keys;  | 
| 
637
 | 
11
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
26
 | 
     unless('ARRAY' eq ref $keys->[0]) {  | 
| 
638
 | 
4
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
10
 | 
         if ($ksize == @$keys) {  | 
| 
639
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
             $keys = [ $keys ];  | 
| 
640
 | 
3
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
240
 | 
             carp "Ambiguous keys list (it was used as ONE key), ".  | 
| 
641
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     "Use brackets to solve the trouble."  | 
| 
642
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         if $ksize > 1 and !$disable_warn;  | 
| 
643
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         } else {  | 
| 
644
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
             $keys = [ map { [ $_ ] } @$keys ];  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
    | 
| 
645
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
646
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
647
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
648
 | 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
176
 | 
     my @res;  | 
| 
649
 | 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16
 | 
     for my $k (@$keys) {  | 
| 
650
 | 
13
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
262
 | 
         croak "key must have $ksize elements" unless $ksize >= @$k;  | 
| 
651
 | 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
         my @packed;  | 
| 
652
 | 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
18
 | 
         for (my $i = 0; $i < @$k; $i++) {  | 
| 
653
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
29
 | 
             my $f = $self->_field($idx->{fields}[$i]);  | 
| 
654
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
35
 | 
             push @packed => $self->pack_field($f->{name}, $k->[$i])  | 
| 
655
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
656
 | 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
22
 | 
         push @res => \@packed;  | 
| 
657
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
658
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
21
 | 
     return \@res;  | 
| 
659
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
660
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
661
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub pack_primary_key {  | 
| 
662
 | 
0
 | 
 
 | 
 
 | 
  
0
  
 | 
 
 | 
0
 | 
     my ($self, $key) = @_;  | 
| 
663
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
664
 | 
0
 | 
  
  0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
0
 | 
     croak 'wrong key format'  | 
| 
665
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         if 'ARRAY' eq ref $key and 'ARRAY' eq ref $key->[0];  | 
| 
666
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
667
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     my $t = $self->pack_keys($key, 0, 1);  | 
| 
668
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     return $t->[0];  | 
| 
669
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
670
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
671
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub pack_operation {  | 
| 
672
 | 
12
 | 
 
 | 
 
 | 
  
12
  
 | 
 
 | 
14
 | 
     my ($self, $op) = @_;  | 
| 
673
 | 
12
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
52
 | 
     croak 'wrong operation' unless 'ARRAY' eq ref $op and @$op > 1;  | 
| 
674
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
675
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
19
 | 
     if ($self->family == 1) {  | 
| 
676
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
         my $fno = $op->[0];  | 
| 
677
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
         my $opname = $op->[1];  | 
| 
678
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
679
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
19
 | 
         my $f = $self->_field($fno);  | 
| 
680
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
681
 | 
12
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
21
 | 
         if ($opname eq 'delete') {  | 
| 
682
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
3
 | 
             croak 'wrong operation' unless @$op == 2;  | 
| 
683
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
             return [ $f->{idx} => $opname ];  | 
| 
684
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
685
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
686
 | 
11
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
38
 | 
         if ($opname =~ /^(?:set|insert|add|and|or|xor)$/) {  | 
| 
687
 | 
9
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
18
 | 
             croak 'wrong operation' unless @$op == 3;  | 
| 
688
 | 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
22
 | 
             return [ $f->{idx} => $opname, $self->pack_field($fno, $op->[2]) ];  | 
| 
689
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
690
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
691
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
6
 | 
         if ($opname eq 'substr') {  | 
| 
692
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
5
 | 
             croak 'wrong operation11' unless @$op >= 4;  | 
| 
693
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
10
 | 
             croak 'wrong offset in substr operation' unless $op->[2] =~ /^\d+$/;  | 
| 
694
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
8
 | 
             croak 'wrong length in substr operation' unless $op->[3] =~ /^\d+$/;  | 
| 
695
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
             return [ $f->{idx}, $opname, $op->[2], $op->[3], $op->[4] ];  | 
| 
696
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
697
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         croak "unknown operation: $opname";  | 
| 
698
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
699
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
700
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     my $fno = $op->[1];  | 
| 
701
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     my $f = $self->_field($fno);  | 
| 
702
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     my @res = @$op;  | 
| 
703
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     splice @res, 1, 1, $f->{idx};  | 
| 
704
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     return \@res;  | 
| 
705
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
706
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
707
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub pack_operations {  | 
| 
708
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
3
 | 
     my ($self, $ops) = @_;  | 
| 
709
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
710
 | 
2
 | 
  
 50
  
 | 
  
 33
  
 | 
 
 | 
 
 | 
17
 | 
     croak 'wrong operation' unless 'ARRAY' eq ref $ops and @$ops >= 1;  | 
| 
711
 | 
2
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
7
 | 
     $ops = [ $ops ] unless 'ARRAY' eq ref $ops->[ 0 ];  | 
| 
712
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
713
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
     my @res;  | 
| 
714
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
     push @res => $self->pack_operation( $_ ) for @$ops;  | 
| 
715
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     return \@res;  | 
| 
716
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
717
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
718
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 COPYRIGHT AND LICENSE  | 
| 
719
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
720
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  Copyright (C) 2011 Dmitry E. Oboukhov   | 
| 
721
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  Copyright (C) 2011 Roman V. Nikolaev   | 
| 
722
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
723
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  This program is free software, you can redistribute it and/or  | 
| 
724
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
  modify it under the terms of the Artistic License.  | 
| 
725
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
726
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 VCS  | 
| 
727
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
728
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 The project is placed git repo on github:  | 
| 
729
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 L.  | 
| 
730
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
731
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
732
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
733
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  |