Array-Sticky
view release on metacpan or search on metacpan
t/sticky-array.t view on Meta::CPAN
use Test::More tests => 10;
use lib grep { -d } qw(./lib ../lib ./t/lib);
use Test::Easy qw(deep_ok);
use Array::Sticky;
my @target;
tie @target, 'Array::Sticky', head => [2], body => [3..7], tail => [8..9];
# the head of the array is locked at [2]
unshift @target, 1;
deep_ok( \@target, [(2), (1, 3..7), (8..9)] ); # the parens are for visual grouping
# the tail is locked at [8, 9]
push @target, 10..12;
deep_ok( \@target, [(2), (1, 3..7, 10..12), (8..9)] );
# shifting leaves the head alone
my @shifted = map { shift(@target) } 0..2;
deep_ok( \@shifted, [1, 3, 4] );
deep_ok( \@target, [(2), (5..7, 10..12), (8..9)] );
# popping leaves the tail alone
my @popped = map { pop(@target) } 0..2;
( run in 0.581 second using v1.01-cache-2.11-cpan-49f99fa48dc )