| MouseX-AttributeHelpers documentation | Contained in the MouseX-AttributeHelpers distribution. |
MouseX::AttributeHelpers::Collection::Array
package MyClass;
use Mouse;
use MouseX::AttributeHelpers;
has 'options' => (
metaclass => 'Collection::Array',
is => 'rw',
isa => 'ArrayRef',
default => sub { [] },
provides => {
count => 'num_options',
empty => 'has_options',
push => 'add_options',
pop => 'remove_last_option',
},
);
This module provides an Array attribute which provides a number of array operations.
This module also consumes the List method providers. See also MouseX::AttributeHelpers::Collection::List.
NAKAGAWA Masaki <masaki@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| MouseX-AttributeHelpers documentation | Contained in the MouseX-AttributeHelpers distribution. |
package MouseX::AttributeHelpers::Collection::Array; use Mouse; use MouseX::AttributeHelpers::Collection::List; extends 'MouseX::AttributeHelpers::Base'; has '+method_constructors' => ( default => sub { my $attr = MouseX::AttributeHelpers::Collection::List->meta->get_attribute('method_constructors'); return +{ %{ $attr->default->() }, # apply MouseX::AttributeHelpers::Collection::List push => sub { my ($attr, $name) = @_; return sub { push @{ shift->$name() } => @_ }; }, pop => sub { my ($attr, $name) = @_; return sub { pop @{ $_[0]->$name() } }; }, unshift => sub { my ($attr, $name) = @_; return sub { unshift @{ shift->$name() } => @_ }; }, shift => sub { my ($attr, $name) = @_; return sub { shift @{ $_[0]->$name() } }; }, get => sub { my ($attr, $name) = @_; return sub { $_[0]->$name()->[$_[1]] }; }, set => sub { my ($attr, $name) = @_; return sub { $_[0]->$name()->[$_[1]] = $_[2] }; }, clear => sub { my ($attr, $name) = @_; return sub { @{ $_[0]->$name() } = () }; }, delete => sub { my ($attr, $name) = @_; return sub { splice @{ $_[0]->$name() }, $_[1], 1 }; }, insert => sub { my ($attr, $name) = @_; return sub { splice @{ $_[0]->$name() }, $_[1], 0, $_[2] }; }, splice => sub { my ($attr, $name) = @_; return sub { my ($self, $offset, $length, @args) = @_; splice @{ $self->$name() }, $offset, $length, @args; }; }, }; }, ); sub helper_type { 'ArrayRef' } no Mouse; __PACKAGE__->meta->make_immutable(inline_constructor => 0); __END__