Acme-Array-MaxSize

 view release on metacpan or  search on metacpan

lib/Acme/Array/MaxSize.pm  view on Meta::CPAN



=head1 SYNOPSIS

Your array will never grow bigger over a given limit.

  use Acme::Array::MaxSize;

  tie my @short, 'Acme::Array::MaxSize', 3;
  @short = (1 .. 10);
  print "@short";  # 1 2 3

=head1 DETAILS

When adding new elements, if the maximal size is reached, all other
elements are thrown away.

  tie my @short, 'Acme::Array::MaxSize', 3;
  @short = ('a');
  push @short, 'b' .. 'h';
  print "@short";  # a b c

Inserting elements at the B<very beginning> behaves differently,
though. Each C<unshift> or C<splice> would insert the maximal possible
number of elements B<at the end> of the inserted list:

  tie my @short, 'Acme::Array::MaxSize', 3;
  @short = ('a');
  unshift @short, 'b' .. 'h';
  print "@short";  # g h a

=head1 AUTHOR

E. Choroba, C<< <choroba at cpan.org> >>

=head1 BUGS

Please report any bugs or feature requests to the GitHub repository
L<https://github.com/choroba/Acme-Array-MaxSize/issues>, or
C<bug-acme-array-maxsize at rt.cpan.org>, or through the web interface

t/00-load.t  view on Meta::CPAN

#!perl -T
use 5.006;
use strict;
use warnings;
use Test::More;

plan tests => 1;

BEGIN {
    use_ok( 'Acme::Array::MaxSize' ) || print "Bail out!\n";
}

diag( "Testing Acme::Array::MaxSize $Acme::Array::MaxSize::VERSION, Perl $], $^X" );



( run in 1.172 second using v1.01-cache-2.11-cpan-de7293f3b23 )