File Coverage

blib/lib/IPC/PrettyPipe/Queue.pm
Criterion Covered Total %
statement 35 35 100.0
branch 5 6 83.3
condition n/a
subroutine 7 7 100.0
pod 2 3 66.6
total 49 51 96.0


line stmt bran cond sub pod time code
1             package IPC::PrettyPipe::Queue;
2              
3             # ABSTRACT: A simple queue
4              
5 17     17   140 use Moo;
  17         47  
  17         165  
6              
7             our $VERSION = '0.13';
8              
9 17     17   7047 use Safe::Isa;
  17         54  
  17         2697  
10 17     17   131 use Types::Standard -types;
  17         48  
  17         186  
11              
12 17     17   78745 use namespace::clean;
  17         46  
  17         172  
13              
14              
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26              
27             sub BUILD {
28              
29 455     455 0 14950 my $self = shift;
30              
31 455 100       781 if ( @{ $self->elements } ) {
  455         7447  
32              
33 2         6 for ( @{ $self->elements } ) {
  2         12  
34 2         9 $_->_set_first( 0 );
35 2         9 $_->_set_last( 0 );
36             }
37              
38 2         13 $self->elements->[0]->_set_first( 1 );
39 2         19 $self->elements->[-1]->_set_last( 1 );
40             }
41             }
42              
43              
44              
45              
46              
47              
48              
49              
50              
51              
52              
53              
54              
55              
56              
57              
58              
59              
60             has elements => (
61             is => 'ro',
62             isa => ArrayRef [ ConsumerOf ['IPC::PrettyPipe::Queue::Element'] ],
63             default => sub { [] },
64             );
65              
66              
67              
68              
69              
70              
71              
72              
73              
74 60     60 1 7135 sub empty { !!!@{ $_[0]->elements } }
  60         289  
75              
76              
77              
78              
79              
80              
81              
82              
83              
84              
85              
86              
87              
88              
89              
90              
91              
92              
93              
94              
95             sub push {
96              
97 411     411 1 9171 my ( $self, $elem ) = ( shift, shift );
98              
99 411 50       1295 die(
100             "attempt to push an incompatible element onto an IPC::PrettyPipe::Queue\n"
101             ) unless $elem->$_does( 'IPC::PrettyPipe::Queue::Element' );
102              
103 411         15964 my $elements = $self->elements;
104              
105 411 100       1086 if ( @$elements ) {
106             ## no critic (ProhibitAccessOfPrivateData)
107 159         580 $elements->[-1]->_set_last( 0 );
108 159         428 $elem->_set_last( 1 );
109 159         389 $elem->_set_first( 0 );
110             }
111             else {
112              
113 252         799 $elem->_set_last( 1 );
114 252         703 $elem->_set_first( 1 );
115              
116             }
117              
118 411         662 push @{$elements}, $elem;
  411         982  
119              
120 411         1134 return;
121             }
122              
123             1;
124              
125             #
126             # This file is part of IPC-PrettyPipe
127             #
128             # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
129             #
130             # This is free software, licensed under:
131             #
132             # The GNU General Public License, Version 3, June 2007
133             #
134              
135             __END__