perlancar

NAME

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

VERSION

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

SYNOPSIS

In lib/Your/Class.pm:

 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->foo(1);
 $obj->bar(2);
 $obj->baz([3,4,5]);

$obj is now:

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

DESCRIPTION

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.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Class-Accessor-Array-Slurpy.

SOURCE

Source repository is at https://github.com/perlancar/perl-Class-Accessor-Array-Slurpy.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Class-Accessor-Array-Slurpy

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.

SEE ALSO

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

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by perlancar@cpan.org.

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