line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Adapter::Async::UnorderedMap::Hash; |
2
|
|
|
|
|
|
|
$Adapter::Async::UnorderedMap::Hash::VERSION = '0.019'; |
3
|
2
|
|
|
2
|
|
16354
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
45
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
43
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
334
|
use parent qw(Adapter::Async::UnorderedMap); |
|
2
|
|
|
|
|
219
|
|
|
2
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Adapter::Async::UnorderedMap::Hash - hashref adapter |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
version 0.018 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
See L for the API. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
2
|
|
|
2
|
1
|
85
|
my $self = shift->SUPER::new(@_); |
24
|
2
|
|
50
|
|
|
20
|
$self->{data} ||= { }; |
25
|
2
|
|
|
|
|
6
|
$self |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub clear { |
29
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
30
|
0
|
|
|
|
|
0
|
%{$self->{data}} = (); |
|
0
|
|
|
|
|
0
|
|
31
|
0
|
|
|
|
|
0
|
$self->bus->invoke_event('clear'); |
32
|
0
|
|
|
|
|
0
|
Future->wrap |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub exists { |
36
|
3
|
|
|
3
|
0
|
731
|
my ($self, $k) = @_; |
37
|
|
|
|
|
|
|
Future->done( |
38
|
3
|
100
|
|
|
|
14
|
exists($self->{data}{$k}) ? 1 : 0 |
39
|
|
|
|
|
|
|
) |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub set_key { |
43
|
2
|
|
|
2
|
0
|
254
|
my ($self, $k, $v) = @_; |
44
|
2
|
|
|
|
|
7
|
$self->{data}{$k} = $v; |
45
|
2
|
|
|
|
|
16
|
$self->bus->invoke_event(set_key => $k, $v); |
46
|
2
|
|
|
|
|
43
|
Future->done($k) |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get_key { |
50
|
2
|
|
|
2
|
0
|
266
|
my ($self, $k, $v) = @_; |
51
|
2
|
50
|
|
|
|
11
|
Future->fail('key does not exist') unless exists $self->{data}{$k}; |
52
|
2
|
|
|
|
|
8
|
Future->done($self->{data}{$k}) |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub each : method { |
56
|
0
|
|
|
0
|
0
|
0
|
my ($self, $code) = @_; |
57
|
0
|
|
|
|
|
0
|
for my $k (keys %{ $self->{data} }) { |
|
0
|
|
|
|
|
0
|
|
58
|
0
|
|
|
|
|
0
|
$code->($k, $self->{data}{$k}) |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
0
|
Future->done; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub keys : method { |
64
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
65
|
|
|
|
|
|
|
Future->done([ |
66
|
0
|
|
|
|
|
0
|
keys %{ $self->{data} } |
|
0
|
|
|
|
|
0
|
|
67
|
|
|
|
|
|
|
]) |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub values : method { |
71
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
72
|
|
|
|
|
|
|
Future->done([ |
73
|
0
|
|
|
|
|
0
|
values %{ $self->{data} } |
|
0
|
|
|
|
|
0
|
|
74
|
|
|
|
|
|
|
]) |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub all { |
78
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
79
|
|
|
|
|
|
|
Future->done(+{ |
80
|
0
|
|
|
|
|
0
|
%{ $self->{data} } |
|
0
|
|
|
|
|
0
|
|
81
|
|
|
|
|
|
|
}) |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# XXX weakrefs |
85
|
|
|
|
|
|
|
sub move { |
86
|
0
|
|
|
0
|
1
|
0
|
my ($self, $idx, $len, $offset) = @_; |
87
|
0
|
|
|
|
|
0
|
my @data = splice @{$self->{data}}, $idx, $len; |
|
0
|
|
|
|
|
0
|
|
88
|
0
|
|
|
|
|
0
|
splice @{$self->{data}}, $idx + $offset, 0, @data; |
|
0
|
|
|
|
|
0
|
|
89
|
0
|
|
|
|
|
0
|
$self->bus->invoke_event(move => $idx, $len, $offset); |
90
|
0
|
|
|
|
|
0
|
Future->wrap($idx, $len, $offset); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# XXX needs updating |
94
|
|
|
|
|
|
|
sub modify { |
95
|
0
|
|
|
0
|
1
|
0
|
my ($self, $k, $data) = @_; |
96
|
0
|
0
|
|
|
|
0
|
die "key does not exist" unless exists $self->{data}{$k}; |
97
|
0
|
|
|
|
|
0
|
$self->{data}{$k} = $data; |
98
|
0
|
|
|
|
|
0
|
$self->bus->invoke_event(modify => $k, $data); |
99
|
0
|
|
|
|
|
0
|
Future->wrap |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub delete { |
103
|
1
|
|
|
1
|
1
|
340
|
my ($self, $k) = @_; |
104
|
1
|
|
|
|
|
3
|
my $v = delete $self->{data}{$k}; |
105
|
1
|
|
|
|
|
3
|
$self->bus->invoke_event(delete => $k, $v); |
106
|
1
|
|
|
|
|
11
|
Future->wrap($k); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 count |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub count { |
114
|
2
|
|
|
2
|
1
|
373
|
my $self = shift; |
115
|
2
|
|
|
|
|
5
|
Future->wrap(scalar keys %{$self->{data}}); |
|
2
|
|
|
|
|
14
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 get |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub get { |
123
|
0
|
|
|
0
|
1
|
|
my ($self, %args) = @_; |
124
|
0
|
0
|
|
|
|
|
return Future->fail('unknown item') if grep !exists $self->{data}{$_}, @{$args{items}}; |
|
0
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my @items = @{$self->{data}}{@{$args{items}}}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
|
if(my $code = $args{on_item}) { |
127
|
0
|
|
|
|
|
|
my @k = @{$args{items}}; |
|
0
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$code->(shift(@k), $_) for @items; |
129
|
|
|
|
|
|
|
} |
130
|
0
|
|
|
|
|
|
Future->wrap(\@items) |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
__END__ |