package FixedSizeQueue; use Moose; has "max_size" => (is => "ro", isa => "Int", default => 10); has "items" => (is => "ro", isa => "ArrayRef", default => sub { [] }); sub pop { my($this)=@_; pop @{$this->items}; } sub push { my($this, $item)=@_; push @{$this->items}, $item; shift @{$this->items} if scalar @{$this->items} > $this->max_size; } #### my $q = FixedSizeQueue->new(max_size => 3); $q->push(3); $q->push(5); $q->push(7); $q->push(9); print Dumper($q); #### sub BUILDARGS { my($this, $max_size)=@_; return { max_size => $max_size }; } #### my $q = FixedSizeQueue->new(3); $q->push(3); $q->push(5); $q->push(7); $q->push(9); print Dumper($q);