package MyClass;
use Moose;
has 'mapping' => (
traits => ['Hash'],
is => 'rw',
isa => 'HashRef[Str]',
default => sub { {} },
handles => {
exists_in_mapping => 'exists',
ids_in_mapping => 'keys',
get_mapping => 'get',
set_mapping => 'set',
set_quantity => [ set => 'quantity' ],
},
);
my $obj = MyClass->new;
$obj->set_quantity(10); # quantity => 10
$obj->set_mapping('foo', 4); # foo => 4
$obj->set_mapping('bar', 5); # bar => 5
$obj->set_mapping('baz', 6); # baz => 6
# prints 5
print $obj->get_mapping('bar') if $obj->exists_in_mapping('bar');
# prints 'quantity, foo, bar, baz'
print join ', ', $obj->ids_in_mapping;
The delegation methods (mostly) map to Perl builtins and operators. The return values of these delegations should be the same as the corresponding Perl operation. Any deviations will be explicitly documented.
See the docs for each native trait for details on what methods are available.
has 'queue' => (
traits => ['Array'],
is => 'ro',
isa => 'ArrayRef[Str]',
default => sub { [] },
handles => {
add_item => 'push',
next_item => 'shift',
# ...
}
);
has 'is_lit' => (
traits => ['Bool'],
is => 'ro',
isa => 'Bool',
default => 0,
handles => {
illuminate => 'set',
darken => 'unset',
flip_switch => 'toggle',
is_dark => 'not',
# ...
}
);
has 'callback' => (
traits => ['Code'],
is => 'ro',
isa => 'CodeRef',
default => sub {
sub {'called'}
},
handles => {
call => 'execute',
# ...
}
);
has 'counter' => (
traits => ['Counter'],
is => 'ro',
isa => 'Num',
default => 0,
handles => {
inc_counter => 'inc',
dec_counter => 'dec',
reset_counter => 'reset',
# ...
}
);
has 'options' => (
traits => ['Hash'],
is => 'ro',
isa => 'HashRef[Str]',
default => sub { {} },
handles => {
set_option => 'set',
get_option => 'get',
has_option => 'exists',
# ...
}
);
has 'integer' => (
traits => ['Number'],
is => 'ro',
isa => 'Int',
default => 5,
handles => {
set => 'set',
add => 'add',
sub => 'sub',
mul => 'mul',
div => 'div',
mod => 'mod',
abs => 'abs',
# ...
}
);
has 'text' => (
traits => ['String'],
is => 'ro',
isa => 'Str',
default => q{},
handles => {
add_text => 'append',
replace_text => 'replace',
# ...
}
);
When the feature was incorporated into the Moose core, some of the API details were changed. The underlying capabilities are the same, but some details of the API were changed.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.