Class::Build::Array::Glob - Generate Class accessors/constructor (array-based object, supports globbing attribute)
This document describes version 0.01 of Class::Build::Array::Glob (from Perl distribution Class-Build-Array-Glob), released on 2016-03-27.
In lib/Your/Class.pm:
package Your::Class; use Class::Build::Array::Glob; has foo => (is => 'rw'); has bar => (is => 'rw'); has baz => (is => 'rw', glob=>1);
In code that uses your class, use your class as usual:
use Your::Class; my $obj = Your::Class->new(foo => 1); $obj->bar(2); my $obj2 = Your::Class->new(foo=>11, bar=>12, baz=>[13, 14, 15]);
$obj1 is now:
$obj1
bless([1, 2], "Your::Class");
$obj2 is now:
$obj2
bless([11, 12, 13, 14, 15], "Your::Class");
This module is a class builder for array-backed classes. With it you can declare your attributes using Moose-style has. Only these has predicates are currently supported: is (ro/rw), glob (bool). Array index will be determined by the order of declaration, so in the example in Synopsis, foo will be stored in element 0, bar in element 1.
has
is
glob
foo
bar
The predicate glob can be specified for the last attribute. It means the attribute has an array value that are put in the end of the object backend array's elements. So in the example in Synopsis, bazvalue's elements will occupy object backend array's elements 2 and subsequent.
baz
There can only be at most one attribute with glob set to true. After the globbing attribute, there can be no more arguments (so subclassing a class with a globbing attribute is not possible).
Note that without globbing attribute, you can still store arrays or other complex data in your attributes. It's just that with a globbing 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 globbing 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 https://metacpan.org/release/Class-Build-Array-Glob.
Source repository is at https://github.com/perlancar/perl-Class-Build-Array-Glob.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Class-Build-Array-Glob
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::XSAccessor::Array, Class::ArrayObjects, Object::ArrayType::New.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2016 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.
To install Class::Build::Array::Glob, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Build::Array::Glob
CPAN shell
perl -MCPAN -e shell install Class::Build::Array::Glob
For more information on module installation, please visit the detailed CPAN module installation guide.