line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Queue::Q::ClaimFIFO::Perl; |
2
|
3
|
|
|
3
|
|
83949
|
use strict; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
73
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
68
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
1050
|
use Queue::Q::ClaimFIFO; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
71
|
|
6
|
3
|
|
|
3
|
|
694
|
use parent 'Queue::Q::ClaimFIFO'; |
|
3
|
|
|
|
|
287
|
|
|
3
|
|
|
|
|
23
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
157
|
use Carp qw(croak); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
138
|
|
9
|
3
|
|
|
3
|
|
15
|
use Scalar::Util qw(refaddr blessed); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
211
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Note: items are generally Queue::Q::ClaimFIFO::Item's |
12
|
3
|
|
|
3
|
|
14
|
use Queue::Q::ClaimFIFO::Item; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1845
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
6
|
|
|
6
|
0
|
394
|
my $class = shift; |
16
|
6
|
|
|
|
|
36
|
my $self = bless { |
17
|
|
|
|
|
|
|
@_, |
18
|
|
|
|
|
|
|
queue => [], |
19
|
|
|
|
|
|
|
claimed => {}, |
20
|
|
|
|
|
|
|
} => $class; |
21
|
6
|
|
|
|
|
19
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# enqueue_item($single_item) |
25
|
|
|
|
|
|
|
sub enqueue_item { |
26
|
116
|
|
|
116
|
1
|
1612
|
my $self = shift; |
27
|
116
|
|
|
|
|
154
|
my $item = shift; |
28
|
|
|
|
|
|
|
|
29
|
116
|
50
|
33
|
|
|
319
|
if (blessed($item) and $item->isa("Queue::Q::ClaimFIFO::Item")) { |
30
|
0
|
|
|
|
|
0
|
croak("Don't pass a Queue::Q::ClaimFIFO::Item object to enqueue_item: " |
31
|
|
|
|
|
|
|
. "Your data structure will be wrapped in one"); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
116
|
|
|
|
|
334
|
$item = Queue::Q::ClaimFIFO::Item->new(item_data => $item); |
35
|
116
|
|
|
|
|
143
|
push @{$self->{queue}}, $item; |
|
116
|
|
|
|
|
215
|
|
36
|
|
|
|
|
|
|
|
37
|
116
|
|
|
|
|
373
|
return $item; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# enqueue_items(@list_of_items) |
41
|
|
|
|
|
|
|
sub enqueue_items { |
42
|
4
|
|
|
4
|
1
|
352
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
5
|
my @items; |
45
|
4
|
|
|
|
|
9
|
for my $item (@_) { |
46
|
41
|
50
|
33
|
|
|
115
|
if (blessed($item) and $item->isa("Queue::Q::ClaimFIFO::Item")) { |
47
|
0
|
|
|
|
|
0
|
croak("Don't pass a Queue::Q::ClaimFIFO::Item object to enqueue_items: " |
48
|
|
|
|
|
|
|
. "Your data structure will be wrapped in one"); |
49
|
|
|
|
|
|
|
} |
50
|
41
|
|
|
|
|
121
|
push @items, Queue::Q::ClaimFIFO::Item->new(item_data => $item); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
4
|
|
|
|
|
7
|
push @{$self->{queue}}, @items; |
|
4
|
|
|
|
|
14
|
|
54
|
4
|
|
|
|
|
15
|
return @items; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# my $item_or_undef = claim_item() |
58
|
|
|
|
|
|
|
sub claim_item { |
59
|
63
|
|
|
63
|
1
|
5047
|
my $self = shift; |
60
|
63
|
|
|
|
|
68
|
my $item = shift @{ $self->{queue} }; |
|
63
|
|
|
|
|
113
|
|
61
|
63
|
100
|
|
|
|
175
|
return undef if not $item; |
62
|
34
|
|
|
|
|
103
|
$self->{claimed}{refaddr($item)} = $item; |
63
|
34
|
|
|
|
|
72
|
return $item; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# my (@items_or_undefs) = claim_items($n) |
67
|
|
|
|
|
|
|
sub claim_items { |
68
|
12
|
|
|
12
|
1
|
1062
|
my $self = shift; |
69
|
12
|
|
100
|
|
|
34
|
my $n = shift || 1; |
70
|
|
|
|
|
|
|
|
71
|
12
|
|
|
|
|
13
|
my @items = splice(@{ $self->{queue} }, 0, $n); |
|
12
|
|
|
|
|
32
|
|
72
|
|
|
|
|
|
|
|
73
|
12
|
|
|
|
|
21
|
my $cl = $self->{claimed}; |
74
|
12
|
|
|
|
|
20
|
for (@items) { |
75
|
23
|
|
|
|
|
76
|
$cl->{refaddr($_)} = $_; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
12
|
|
|
|
|
35
|
return @items; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# mark_item_as_done($item_previously_claimed) |
82
|
|
|
|
|
|
|
sub mark_item_as_done { |
83
|
50
|
|
|
50
|
1
|
1826
|
my $self = shift; |
84
|
50
|
|
|
|
|
57
|
my $item = shift; |
85
|
50
|
|
|
|
|
141
|
delete $self->{claimed}{refaddr($item)}; |
86
|
50
|
|
|
|
|
132
|
return 1; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# mark_item_as_done(@items_previously_claimed) |
90
|
|
|
|
|
|
|
sub mark_items_as_done { |
91
|
1
|
|
|
1
|
1
|
351
|
my $self = shift; |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
3
|
foreach (@_) { |
94
|
8
|
50
|
|
|
|
13
|
next if not defined $_; |
95
|
8
|
|
|
|
|
26
|
delete $self->{claimed}{refaddr($_)}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
3
|
return 1; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub flush_queue { |
102
|
11
|
|
|
11
|
1
|
747
|
my $self = shift; |
103
|
11
|
|
|
|
|
16
|
@{ $self->{queue} } = (); |
|
11
|
|
|
|
|
49
|
|
104
|
11
|
|
|
|
|
15
|
%{ $self->{claimed} } = (); |
|
11
|
|
|
|
|
33
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# my $nitems = queue_length() |
108
|
|
|
|
|
|
|
sub queue_length { |
109
|
76
|
|
|
76
|
1
|
7550
|
my $self = shift; |
110
|
76
|
|
|
|
|
96
|
return scalar( @{ $self->{queue} } ); |
|
76
|
|
|
|
|
239
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# my $nclaimed_items = claimed_count() |
114
|
|
|
|
|
|
|
sub claimed_count { |
115
|
66
|
|
|
66
|
0
|
76
|
my $self = shift; |
116
|
66
|
|
|
|
|
75
|
return scalar( keys %{ $self->{claimed} } ); |
|
66
|
|
|
|
|
229
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
__END__ |