line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Array::Queue; |
2
|
|
|
|
|
|
|
$Array::Queue::VERSION = '0.1.1'; |
3
|
2
|
|
|
2
|
|
73154
|
use Moose; |
|
2
|
|
|
|
|
310079
|
|
|
2
|
|
|
|
|
9
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
8264
|
use namespace::autoclean; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
12
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Array::Queue - A simple fifo queue |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
version 0.1.1 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $queue = Array::Queue->new; |
19
|
|
|
|
|
|
|
$ar->add({ id => 20 }); |
20
|
|
|
|
|
|
|
$ar->add({ id => 18 }); |
21
|
|
|
|
|
|
|
$ar->add({ id => 22 }); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
while ($node = $queue->first) { |
24
|
|
|
|
|
|
|
# do things with node |
25
|
|
|
|
|
|
|
$queue->remove; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Array::Queue is a fairly simple First-In / First-Out queue build with Moose. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Any data structure can be added to the queue and retrieved in the order it was |
33
|
|
|
|
|
|
|
added. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Originally part of Array::Queue::Priority until I decided to break them into two |
36
|
|
|
|
|
|
|
classes, the one dependant on the other. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 METHODS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 C<add> |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$ar->add( 99 ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
You can add any type of item to the queue. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 C<remove> |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$ar->remove; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Remove the oldest item on the queue. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Returns value removed. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 C<first> |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$ar->first; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Returns the first / oldest item in the queue. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Leaves the item in the queue. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 C<queue> |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$ar->queue; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Reference directly the array used to store the queued items. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 C<size> |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$ar->size; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
How many elements are in the queue. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 C<empty> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$ar->empty; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Boolean, is queue empty? |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Dan Burke C<< dburke at addictmud.org >> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 BUGS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
If you encounter any bugs, or have feature requests, please create an issue |
88
|
|
|
|
|
|
|
on github. https://github.com/dwburke/perl-Array-Queue/issues |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Pull requests also welcome. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
L<http://www.perlfoundation.org/artistic_license_2_0> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub first { |
100
|
30
|
|
|
30
|
1
|
753
|
my ($self) = @_; |
101
|
30
|
|
|
|
|
728
|
$self->get(0); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
has queue => ( |
106
|
|
|
|
|
|
|
is => 'rw', |
107
|
|
|
|
|
|
|
isa => 'ArrayRef[Item]', |
108
|
|
|
|
|
|
|
traits => [ 'Array' ], |
109
|
|
|
|
|
|
|
default => sub { [ ] }, |
110
|
|
|
|
|
|
|
handles => { |
111
|
|
|
|
|
|
|
add => 'push', |
112
|
|
|
|
|
|
|
remove => 'shift', |
113
|
|
|
|
|
|
|
size => 'count', |
114
|
|
|
|
|
|
|
get => 'get', |
115
|
|
|
|
|
|
|
empty => 'is_empty', |
116
|
|
|
|
|
|
|
_insert => 'insert', |
117
|
|
|
|
|
|
|
}, |
118
|
|
|
|
|
|
|
); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |