| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
##################################################################### |
|
2
|
|
|
|
|
|
|
## AUTHOR: Mary Ehlers, regina.verbae@gmail.com |
|
3
|
|
|
|
|
|
|
## ABSTRACT: Simple FIFO queue used by Piper |
|
4
|
|
|
|
|
|
|
##################################################################### |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Piper::Queue; |
|
7
|
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
1976
|
use v5.10; |
|
|
3
|
|
|
|
|
7
|
|
|
9
|
3
|
|
|
3
|
|
11
|
use strict; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
57
|
|
|
10
|
3
|
|
|
3
|
|
10
|
use warnings; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
83
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
504
|
use Types::Standard qw(ArrayRef); |
|
|
3
|
|
|
|
|
78873
|
|
|
|
3
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
1928
|
use Moo; |
|
|
3
|
|
|
|
|
10305
|
|
|
|
3
|
|
|
|
|
17
|
|
|
15
|
3
|
|
|
3
|
|
2740
|
use namespace::clean; |
|
|
3
|
|
|
|
|
12892
|
|
|
|
3
|
|
|
|
|
22
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
with 'Piper::Role::Queue'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.04'; # from Piper-0.04.tar.gz |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
|
22
|
|
|
|
|
|
|
#pod |
|
23
|
|
|
|
|
|
|
#pod =for stopwords dequeued |
|
24
|
|
|
|
|
|
|
#pod |
|
25
|
|
|
|
|
|
|
#pod use Piper::Queue; |
|
26
|
|
|
|
|
|
|
#pod |
|
27
|
|
|
|
|
|
|
#pod my $queue = Piper::Queue->new(); |
|
28
|
|
|
|
|
|
|
#pod $queue->enqueue(qw(x y)); |
|
29
|
|
|
|
|
|
|
#pod $queue->ready; # 2 |
|
30
|
|
|
|
|
|
|
#pod $queue->dequeue; # 'x' |
|
31
|
|
|
|
|
|
|
#pod $queue->requeue('x'); |
|
32
|
|
|
|
|
|
|
#pod $queue->dequeue; # 'x' |
|
33
|
|
|
|
|
|
|
#pod |
|
34
|
|
|
|
|
|
|
#pod =head1 CONSTRUCTOR |
|
35
|
|
|
|
|
|
|
#pod |
|
36
|
|
|
|
|
|
|
#pod =head2 new |
|
37
|
|
|
|
|
|
|
#pod |
|
38
|
|
|
|
|
|
|
#pod =cut |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has queue => ( |
|
41
|
|
|
|
|
|
|
is => 'ro', |
|
42
|
|
|
|
|
|
|
isa => ArrayRef, |
|
43
|
|
|
|
|
|
|
default => sub { [] }, |
|
44
|
|
|
|
|
|
|
); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#pod =head1 METHODS |
|
47
|
|
|
|
|
|
|
#pod |
|
48
|
|
|
|
|
|
|
#pod =head2 dequeue($num) |
|
49
|
|
|
|
|
|
|
#pod |
|
50
|
|
|
|
|
|
|
#pod Remove and return at most C<$num> items from the queue. The default S is 1>. |
|
51
|
|
|
|
|
|
|
#pod |
|
52
|
|
|
|
|
|
|
#pod If C<$num> is greater than the number of items remaining in the queue, only the number remaining will be dequeued. |
|
53
|
|
|
|
|
|
|
#pod |
|
54
|
|
|
|
|
|
|
#pod Returns an array of items if wantarray, otherwise returns the last of the dequeued items, which allows singleton dequeues: |
|
55
|
|
|
|
|
|
|
#pod |
|
56
|
|
|
|
|
|
|
#pod my @results = $queue->dequeue($num); |
|
57
|
|
|
|
|
|
|
#pod my $single = $queue->dequeue; |
|
58
|
|
|
|
|
|
|
#pod |
|
59
|
|
|
|
|
|
|
#pod =cut |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub dequeue { |
|
62
|
179
|
|
|
179
|
1
|
11760
|
my ($self, $num) = @_; |
|
63
|
179
|
|
100
|
|
|
367
|
$num //= 1; |
|
64
|
179
|
|
|
|
|
138
|
splice @{$self->queue}, 0, $num; |
|
|
179
|
|
|
|
|
738
|
|
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#pod =head2 enqueue(@items) |
|
68
|
|
|
|
|
|
|
#pod |
|
69
|
|
|
|
|
|
|
#pod Add C<@items> to the queue. |
|
70
|
|
|
|
|
|
|
#pod |
|
71
|
|
|
|
|
|
|
#pod =cut |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub enqueue { |
|
74
|
184
|
|
|
184
|
1
|
2713
|
my $self = shift; |
|
75
|
184
|
|
|
|
|
150
|
push @{$self->queue}, @_; |
|
|
184
|
|
|
|
|
857
|
|
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#pod =head2 ready |
|
79
|
|
|
|
|
|
|
#pod |
|
80
|
|
|
|
|
|
|
#pod Returns the number of elements in the queue. |
|
81
|
|
|
|
|
|
|
#pod |
|
82
|
|
|
|
|
|
|
#pod =cut |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub ready { |
|
85
|
1022
|
|
|
1022
|
1
|
21103
|
my ($self) = @_; |
|
86
|
1022
|
|
|
|
|
702
|
return scalar @{$self->queue}; |
|
|
1022
|
|
|
|
|
6601
|
|
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
#pod =head2 requeue(@items) |
|
90
|
|
|
|
|
|
|
#pod |
|
91
|
|
|
|
|
|
|
#pod Inserts C<@items> to the top of the queue in an order such that C would subsequently return C<$items[0]> and so forth. |
|
92
|
|
|
|
|
|
|
#pod |
|
93
|
|
|
|
|
|
|
#pod =cut |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub requeue { |
|
96
|
8
|
|
|
8
|
1
|
1505
|
my $self = shift; |
|
97
|
8
|
|
|
|
|
12
|
unshift @{$self->queue}, @_; |
|
|
8
|
|
|
|
|
29
|
|
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |