my $obj = MyClass->new;
$obj->set_quantity(10); # quantity => 10
- $obj->set_mapping(4, 'foo'); # 4 => 'foo'
- $obj->set_mapping(5, 'bar'); # 5 => 'bar'
- $obj->set_mapping(6, 'baz'); # 6 => 'baz'
+ $obj->set_mapping('foo', 4); # foo => 4
+ $obj->set_mapping('bar', 5); # bar => 5
+ $obj->set_mapping('baz', 6); # baz => 6
- # prints 'bar'
- print $obj->get_mapping(5) if $obj->exists_in_mapping(5);
+ # prints 5
+ print $obj->get_mapping('bar') if $obj->exists_in_mapping('bar');
- # prints '4, 5, 6'
+ # prints 'quantity, foo, bar, baz'
print join ', ', $obj->ids_in_mapping;
=head1 DESCRIPTION
While L<Moose> attributes provide a way to name your accessors, readers,
-writers, clearers and predicates, this library provides commonly
+writers, clearers and predicates, this set of traits provides commonly
used attribute helper methods for more specific types of data.
As seen in the L</SYNOPSIS>, you specify the data structure via the
-C<trait> parameter. Available meta classes are below; see L</METHOD PROVIDERS>.
+C<trait> parameter. Available traits are below; see L</METHOD PROVIDERS>.
This module used to exist as the L<MooseX::AttributeHelpers> extension. It was
very commonly used, so we moved it into core Moose. Since this gave us a chance
to change the interface, you will have to change your code or continue using
-the L<MooseX::AttributeHelpers> extension.
+the L<MooseX::AttributeHelpers> extension. L<MooseX::AttributeHelpers> should
+continue to work.
=head1 PARAMETERS
=head1 NAME
-Moose::Meta::Attribute::Native::Trait::Number
+Moose::Meta::Attribute::Native::Trait::Number - Helper trait for Num attributes
=head1 SYNOPSIS
use Moose;
has 'integer' => (
- metaclass => 'Number',
+ traits => ['Number'],
is => 'ro',
- isa => 'Int',
+ isa => 'Num',
default => 5,
handles => {
set => 'set',
=item B<sub($value)>
-Subtracts the current value of the attribute to C<$value>.
+Subtracts C<$value> from the current value of the attribute.
=item B<mul($value)>
-Multiplies the current value of the attribute to C<$value>.
+Multiplies the current value of the attribute by C<$value>.
=item B<div($value)>
-Divides the current value of the attribute to C<$value>.
+Divides the current value of the attribute by C<$value>.
=item B<mod($value)>
-Modulus the current value of the attribute to C<$value>.
+Returns the current value of the attribute modulo C<$value>.
=item B<abs>
=head1 NAME
-Moose::Meta::Attribute::Native::Trait::String
+Moose::Meta::Attribute::Native::Trait::String - Helper trait for Str attributes
=head1 SYNOPSIS
If your attribute definition does not include any of I<is>, I<isa>,
I<default> or I<handles> but does use the C<String> metaclass,
then this module applies defaults as in the L</SYNOPSIS>
-above. This allows for a very basic counter definition:
+above. This allows for a very basic string definition:
- has 'foo' => (metaclass => 'String');
+ has 'foo' => (traits => ['String']);
$obj->append_foo;
=head1 PROVIDED METHODS
These methods are implemented in
-L<Moose::Meta::Attribute::Native::MethodProvider::STring>. It is important to
+L<Moose::Meta::Attribute::Native::MethodProvider::String>. It is important to
note that all those methods do in place modification of the value stored in
the attribute.