line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Collect |
2
|
|
|
|
|
|
|
package ONE::Collect; |
3
|
|
|
|
|
|
|
{ |
4
|
|
|
|
|
|
|
$ONE::Collect::VERSION = 'v0.2.0'; |
5
|
|
|
|
|
|
|
} |
6
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
74
|
|
7
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
57
|
|
8
|
2
|
|
|
2
|
|
9
|
use AnyEvent; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
33
|
|
9
|
2
|
|
|
2
|
|
1937
|
use Any::Moose; |
|
2
|
|
|
|
|
71867
|
|
|
2
|
|
|
|
|
18
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has '_cv' => (isa=>'AnyEvent::CondVar', is=>'rw'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub listener { |
15
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
16
|
2
|
|
|
|
|
4
|
my( $todo ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Create a new CV if we don't have one yet |
19
|
2
|
|
|
|
|
6
|
my $cv = $self->_cv; |
20
|
2
|
100
|
|
|
|
8
|
unless ( $cv ) { |
21
|
1
|
|
|
|
|
34
|
$self->_cv( $cv = AE::cv ); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Begin processing |
25
|
2
|
|
|
|
|
32
|
$cv->begin; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Here we wrap the event listener and, after the first call, remove ourselves |
28
|
2
|
|
|
|
|
9
|
my $wrapped; |
29
|
|
|
|
|
|
|
$wrapped = sub { |
30
|
2
|
|
|
2
|
|
138
|
my $self = shift; |
31
|
2
|
|
|
|
|
19
|
$self->remove_listener( $self->current_event, $wrapped ); |
32
|
2
|
|
|
|
|
124
|
$self->on( $self->current_event, $todo ); |
33
|
2
|
|
|
|
|
130
|
$todo->(@_); |
34
|
2
|
|
|
|
|
25
|
$cv->end; |
35
|
2
|
|
|
|
|
42
|
undef $wrapped; |
36
|
2
|
|
|
|
|
9
|
}; |
37
|
2
|
|
|
|
|
9
|
return $wrapped; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub complete { |
43
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
44
|
1
|
50
|
|
|
|
7
|
return unless defined $self->_cv; |
45
|
1
|
|
|
|
|
9
|
$self->_cv->wait; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
50
|
2
|
|
|
2
|
|
1628
|
no Any::Moose; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |