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
|
|
3187
|
use v5.10; |
|
3
|
|
|
|
|
7
|
|
9
|
3
|
|
|
3
|
|
12
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
51
|
|
10
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
78
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
487
|
use Types::Standard qw(ArrayRef); |
|
3
|
|
|
|
|
47134
|
|
|
3
|
|
|
|
|
25
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
1862
|
use Moo; |
|
3
|
|
|
|
|
7614
|
|
|
3
|
|
|
|
|
17
|
|
15
|
3
|
|
|
3
|
|
1915
|
use namespace::clean; |
|
3
|
|
|
|
|
7687
|
|
|
3
|
|
|
|
|
17
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
with 'Piper::Role::Queue'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.03'; # from Piper-0.03.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
|
13375
|
my ($self, $num) = @_; |
63
|
179
|
|
100
|
|
|
355
|
$num //= 1; |
64
|
179
|
|
|
|
|
122
|
splice @{$self->queue}, 0, $num; |
|
179
|
|
|
|
|
733
|
|
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
|
2738
|
my $self = shift; |
75
|
184
|
|
|
|
|
132
|
push @{$self->queue}, @_; |
|
184
|
|
|
|
|
804
|
|
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
|
22819
|
my ($self) = @_; |
86
|
1022
|
|
|
|
|
663
|
return scalar @{$self->queue}; |
|
1022
|
|
|
|
|
6470
|
|
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
|
2628
|
my $self = shift; |
97
|
8
|
|
|
|
|
9
|
unshift @{$self->queue}, @_; |
|
8
|
|
|
|
|
33
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |