line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Queue::Q::ClaimFIFO::Perl; |
2
|
3
|
|
|
3
|
|
88663
|
use strict; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
78
|
|
3
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
70
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
1064
|
use Queue::Q::ClaimFIFO; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
77
|
|
6
|
3
|
|
|
3
|
|
767
|
use parent 'Queue::Q::ClaimFIFO'; |
|
3
|
|
|
|
|
336
|
|
|
3
|
|
|
|
|
24
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
160
|
use Carp qw(croak); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
152
|
|
9
|
3
|
|
|
3
|
|
14
|
use Scalar::Util qw(refaddr blessed); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
225
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Note: items are generally Queue::Q::ClaimFIFO::Item's |
12
|
3
|
|
|
3
|
|
13
|
use Queue::Q::ClaimFIFO::Item; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1933
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
6
|
|
|
6
|
0
|
720
|
my $class = shift; |
16
|
6
|
|
|
|
|
42
|
my $self = bless { |
17
|
|
|
|
|
|
|
@_, |
18
|
|
|
|
|
|
|
queue => [], |
19
|
|
|
|
|
|
|
claimed => {}, |
20
|
|
|
|
|
|
|
} => $class; |
21
|
6
|
|
|
|
|
25
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# enqueue_item($single_item) |
25
|
|
|
|
|
|
|
sub enqueue_item { |
26
|
116
|
|
|
116
|
1
|
2263
|
my $self = shift; |
27
|
116
|
|
|
|
|
146
|
my $item = shift; |
28
|
|
|
|
|
|
|
|
29
|
116
|
50
|
33
|
|
|
317
|
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
|
|
|
|
|
360
|
$item = Queue::Q::ClaimFIFO::Item->new(item_data => $item); |
35
|
116
|
|
|
|
|
155
|
push @{$self->{queue}}, $item; |
|
116
|
|
|
|
|
235
|
|
36
|
|
|
|
|
|
|
|
37
|
116
|
|
|
|
|
397
|
return $item; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# enqueue_items(@list_of_items) |
41
|
|
|
|
|
|
|
sub enqueue_items { |
42
|
4
|
|
|
4
|
1
|
1046
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
7
|
my @items; |
45
|
4
|
|
|
|
|
10
|
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
|
|
|
|
|
135
|
push @items, Queue::Q::ClaimFIFO::Item->new(item_data => $item); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
4
|
|
|
|
|
6
|
push @{$self->{queue}}, @items; |
|
4
|
|
|
|
|
16
|
|
54
|
4
|
|
|
|
|
16
|
return @items; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# my $item_or_undef = claim_item() |
58
|
|
|
|
|
|
|
sub claim_item { |
59
|
63
|
|
|
63
|
1
|
7733
|
my $self = shift; |
60
|
63
|
|
|
|
|
75
|
my $item = shift @{ $self->{queue} }; |
|
63
|
|
|
|
|
130
|
|
61
|
63
|
100
|
|
|
|
195
|
return undef if not $item; |
62
|
34
|
|
|
|
|
119
|
$self->{claimed}{refaddr($item)} = $item; |
63
|
34
|
|
|
|
|
78
|
return $item; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# my (@items_or_undefs) = claim_items($n) |
67
|
|
|
|
|
|
|
sub claim_items { |
68
|
12
|
|
|
12
|
1
|
1511
|
my $self = shift; |
69
|
12
|
|
100
|
|
|
53
|
my $n = shift || 1; |
70
|
|
|
|
|
|
|
|
71
|
12
|
|
|
|
|
21
|
my @items = splice(@{ $self->{queue} }, 0, $n); |
|
12
|
|
|
|
|
59
|
|
72
|
|
|
|
|
|
|
|
73
|
12
|
|
|
|
|
81
|
my $cl = $self->{claimed}; |
74
|
12
|
|
|
|
|
37
|
for (@items) { |
75
|
23
|
|
|
|
|
115
|
$cl->{refaddr($_)} = $_; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
12
|
|
|
|
|
70
|
return @items; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# mark_item_as_done($item_previously_claimed) |
82
|
|
|
|
|
|
|
sub mark_item_as_done { |
83
|
50
|
|
|
50
|
1
|
2890
|
my $self = shift; |
84
|
50
|
|
|
|
|
77
|
my $item = shift; |
85
|
50
|
|
|
|
|
170
|
delete $self->{claimed}{refaddr($item)}; |
86
|
50
|
|
|
|
|
129
|
return 1; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# mark_item_as_done(@items_previously_claimed) |
90
|
|
|
|
|
|
|
sub mark_items_as_done { |
91
|
1
|
|
|
1
|
1
|
518
|
my $self = shift; |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
3
|
foreach (@_) { |
94
|
8
|
50
|
|
|
|
17
|
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
|
1289
|
my $self = shift; |
103
|
11
|
|
|
|
|
16
|
@{ $self->{queue} } = (); |
|
11
|
|
|
|
|
55
|
|
104
|
11
|
|
|
|
|
19
|
%{ $self->{claimed} } = (); |
|
11
|
|
|
|
|
40
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# my $nitems = queue_length() |
108
|
|
|
|
|
|
|
sub queue_length { |
109
|
76
|
|
|
76
|
1
|
11241
|
my $self = shift; |
110
|
76
|
|
|
|
|
111
|
return scalar( @{ $self->{queue} } ); |
|
76
|
|
|
|
|
354
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# my $nclaimed_items = claimed_count() |
114
|
|
|
|
|
|
|
sub claimed_count { |
115
|
66
|
|
|
66
|
0
|
133
|
my $self = shift; |
116
|
66
|
|
|
|
|
103
|
return scalar( keys %{ $self->{claimed} } ); |
|
66
|
|
|
|
|
360
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
__END__ |