I am starting to understand that this is for beginners:
package Bad; has 'arr' => ( is => 'rw', 'ArrayRef[Str]' ); package main; my $bad = Bad->new(arr => [ "foo", "bar" ]); print $bad->arr->[0], "\n";
Enter the characteristics. However, the APIs are haunting me. Am I misunderstood something? Can I get this API as well?
print $bad->arr->get(0), "\n";
More details
Check out an example of canonical features from Moose :: Meta :: Attribute :: Native :: Trait :: Array
package Stuff; use Moose; has 'options' => ( traits => ['Array'], is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] }, handles => { all_options => 'elements', add_option => 'push', map_options => 'map', filter_options => 'grep', find_option => 'first', get_option => 'get', join_options => 'join', count_options => 'count', has_options => 'count', has_no_options => 'is_empty', sorted_options => 'sort', }, ); no Moose; 1;
Such an object is used, for example:
my $option = $stuff->get_option(1);
I really don't like this for the single array attribute that I get, and I need to manually call 11 methods in the Stuff class - one for each individual operation that can be used for "options". Inconsistent naming should happen, and it swells.
How do I (elegantly) get an API like:
my $option = $stuff->options->get(1);
Where are all the methods from Moose :: Meta :: Attribute :: Native :: Trait :: Array implemented in a safe type way?
Then all operations on each one array are called exactly the same ...
(I actually use Mouse, but most of Mouse is identical to Moose)