use 5.16.2; package fQ_moonimal { use Moo; use overload '""' => sub { join $", @{+shift->items} }; has size => is => "ro", default => sub { 10 }, isa => sub { die "size must be a positive integer" unless $_[0] > 0 }; has items => is => "ro", init_arg => undef, default => sub { [] }; sub push { my ( $self, $item ) = @_; push @{$self->items}, $item; pop @{$self->items} if @{$self->items} > $self->size; } sub pop { pop @{+shift->items}; } }; package fQ_moofancy { use Moo; use MooX::HandlesVia; use MooX::late; use overload '""' => sub { join $", +shift->all }; # More are avaialbe. my @methods = qw/ push pop count all shift unshift natatime /; has size => is => "ro", required => 1, isa => sub { die "size must be a positive integer" unless $_[0] and $_[0] > 0 }; has items => is => "ro", init_args => undef, traits => ["Array"], handles => { map { $_ => $_ } @methods }, default => sub { [] }; after "push" => sub { my $self = shift; $self->shift until $self->size >= $self->count; }; after "unshift" => sub { my $self = shift; $self->pop until $self->size >= $self->count; }; sub BUILDARGS { my $class = shift; my $size = shift; die "Only one argument allowed: size" if @_; { size => $size }; } }; package fQ_FIXED { use overload '""' => sub { join $", map $_ || "_", @{+shift} }; sub new { bless [ (undef) x $_[1] ], __PACKAGE__ } sub push { my $self = shift; push @{$self}, shift; shift @{$self}; } sub pop { my $self = shift; unshift @{$self}, undef; pop @{$self}; } };