File Coverage

blib/lib/Net/Async/Beanstalk/Stack.pm
Criterion Covered Total %
statement 15 16 93.7
branch 0 2 0.0
condition n/a
subroutine 5 6 83.3
pod 1 1 100.0
total 21 25 84.0


line stmt bran cond sub pod time code
1             package Net::Async::Beanstalk::Stack;
2              
3             our $VERSION = '0.001';
4             $VERSION = eval $VERSION;
5              
6             =head1 NAME
7              
8             Net::Async::Beanstalk::Stack - A FIFO stack of queued commands
9              
10             =head1 DOCUMENTED ELSEWHERE
11              
12             This module's external API is undocumented.
13              
14             =cut
15              
16 3     3   24395 use Moo::Role;
  3         8  
  3         18  
17 3     3   922 use strictures 2;
  3         24  
  3         128  
18              
19 3     3   616 use Carp;
  3         6  
  3         227  
20 3     3   1251 use MooX::HandlesVia;
  3         1877  
  3         28  
21 3     3   255 use namespace::clean;
  3         11  
  3         20  
22              
23             # TODO: Document internal API
24              
25             =head1 ATTRIBUTES
26              
27             =over
28              
29             =item _command_stack
30              
31             =for comment Documented last because this attribue isn't particularly
32             interesting to users of this module.
33              
34             An internal FIFO stack of commands which are waiting to be sent or
35             responded to.
36              
37             Accessors:
38              
39             =over
40              
41             =item count_commands
42              
43             How many commands are in the stack, including the one which the server
44             is currently processing.
45              
46             =item current_command
47              
48             Returns the command the server is currently processing, or has just
49             sent a response to, without removing it from the stack.
50              
51             =item is_busy
52              
53             A boolean indicating whether the client is busy, ie. has a command
54             currently being processed or has commands waiting to be sent. Actually
55             implemented by the same method as L.
56              
57             =item _pending_commands
58              
59             Returns the commands which have not yet completed, including the one
60             which the server is currently processing.
61              
62             =item _push_command
63              
64             Push a new command onto the stack.
65              
66             =item _shift_command
67              
68             Remove and return the first command from the stack, which the server
69             is either processing or has returned a response to.
70              
71             =back
72              
73             =cut
74              
75             has _command_stack => (
76             is => 'ro',
77             init_arg => undef,
78             default => sub { [] },
79             handles_via => 'Array',
80             handles => {
81             count_commands => 'count',
82             is_busy => 'count',
83             _pending_commands => 'all',
84             _push_command => 'push',
85             _shift_command => 'shift',
86             },
87             );
88              
89 0 0   0 1   sub current_command { $_[0]->_command_stack->[0] || croak "No active command" }
90              
91             =back
92              
93             =cut
94              
95             1;