Class::Accessor::Array::Slurpy - Generate accessors/constructor for array-based object (supports slurpy attribute)


This document describes version 0.020 of Class::Accessor::Array::Slurpy (from Perl distribution Class-Accessor-Array-Slurpy), released on 2017-09-13.


In lib/Your/

 package Your::Class;
 use Class::Accessor::Array::Slurpy {
     accessors => {
         foo => 0,
         bar => 1,
         baz => 2,
     slurpy_attribute => 'baz',

In code that uses your class:

 use Your::Class;

 my $obj = Your::Class->new;

$obj is now:

 bless([1, 2, 3, 4, 5], "Your::Class");


This module is a builder for array-backed classes. It is the same as Class::Accessor::Array except that you can define your last (in term of the index in array storage) attribute to be a "slurpy attribute", meaning it is an array where its elements are stored as elements of the array storage. There can be at most one slurpy attribute and it must be the last.

Note that without a slurpy attribute, you can still store arrays or other complex data in your attributes. It's just that with a slurpy attribute, you can keep a single flat array backend, so the overall number of arrays is minimized.

An example of application: tree node objects, where the first attribute (array element) is the parent, then zero or more extra attributes, then the last attribute is a slurpy one storing zero or more children. This is how Mojo::DOM stores its HTML tree node, for example.


Please visit the project's homepage at


Source repository is at


Please report any bugs or feature requests on the bugtracker website

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.


Other class builders for array-backed objects: Class::Accessor::Array, Class::XSAccessor::Array, Class::ArrayObjects, Object::ArrayType::New.


perlancar <>


This software is copyright (c) 2017 by

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.