| 1 | package IPC::PrettyPipe::Queue; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: A simple queue | ||||||||||
| 4 | |||||||||||
| 5 | 21 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 21 | our $VERSION = '0.13'; | |||||||||
| 8 | |||||||||||
| 9 | 21 | ▶ | use Safe::Isa; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 21 | ▶ | use Types::Standard -types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 21 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | 455 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 28 | |||||||||||
| 29 | 455 | my $self = shift; | |||||||||
| 30 | |||||||||||
| 31 | 455 | ▶ | if ( @{ $self->elements } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | 2 | for ( @{ $self->elements } ) { | |||||||||
| 34 | 2 | $_->_set_first( 0 ); | |||||||||
| 35 | 2 | $_->_set_last( 0 ); | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 2 | $self->elements->[0]->_set_first( 1 ); | |||||||||
| 39 | 2 | $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 | 390 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 21 | ); | |||||||||
| 65 | |||||||||||
| 66 | |||||||||||
| 67 | |||||||||||
| 68 | |||||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | |||||||||||
| 72 | |||||||||||
| 73 | |||||||||||
| 74 | 60 | ▶ | sub empty { !!!@{ $_[0]->elements } } | ||||||||
|
Subroutine
empty: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 75 | |||||||||||
| 76 | |||||||||||
| 77 | |||||||||||
| 78 | |||||||||||
| 79 | |||||||||||
| 80 | |||||||||||
| 81 | |||||||||||
| 82 | |||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | |||||||||||
| 88 | |||||||||||
| 89 | |||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | |||||||||||
| 93 | |||||||||||
| 94 | |||||||||||
| 95 | 411 | ▶ | sub push { | ||||||||
|
Subroutine
push: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 96 | |||||||||||
| 97 | 411 | my ( $self, $elem ) = ( shift, shift ); | |||||||||
| 98 | |||||||||||
| 99 | 411 | ▶ | die( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | "attempt to push an incompatible element onto an IPC::PrettyPipe::Queue\n" | ||||||||||
| 101 | ) unless $elem->$_does( 'IPC::PrettyPipe::Queue::Element' ); | ||||||||||
| 102 | |||||||||||
| 103 | 411 | my $elements = $self->elements; | |||||||||
| 104 | |||||||||||
| 105 | 411 | ▶ | if ( @$elements ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | ## no critic (ProhibitAccessOfPrivateData) | ||||||||||
| 107 | 159 | $elements->[-1]->_set_last( 0 ); | |||||||||
| 108 | 159 | $elem->_set_last( 1 ); | |||||||||
| 109 | 159 | $elem->_set_first( 0 ); | |||||||||
| 110 | } | ||||||||||
| 111 | else { | ||||||||||
| 112 | |||||||||||
| 113 | 252 | $elem->_set_last( 1 ); | |||||||||
| 114 | 252 | $elem->_set_first( 1 ); | |||||||||
| 115 | |||||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | 411 | push @{$elements}, $elem; | |||||||||
| 119 | |||||||||||
| 120 | 411 | return; | |||||||||
| 121 | } | ||||||||||
| 122 | |||||||||||
| 123 | 21 | 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__ | ||||||||||