X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FAttribute%2FNative.pm;h=2487ba5fac0aaab1a7aaae2ae95872741ffa2517;hb=eaf5a43ef108f6a9dce74c84afc25a892cffdfb1;hp=105616ff6ce06d9ddaa91b646db4c5a4ddb8f070;hpb=122a129ac1b02a53a4ac31f848a9bc89ce8feacf;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Attribute/Native.pm b/lib/Moose/Meta/Attribute/Native.pm index 105616f..2487ba5 100644 --- a/lib/Moose/Meta/Attribute/Native.pm +++ b/lib/Moose/Meta/Attribute/Native.pm @@ -1,10 +1,10 @@ package Moose::Meta::Attribute::Native; -our $VERSION = '0.89'; +our $VERSION = '0.90'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -my @trait_names = qw(Bool Counter Number String Array Hash); +my @trait_names = qw(Bool Counter Number String Array Hash Code); for my $trait_name (@trait_names) { my $trait_class = "Moose::Meta::Attribute::Native::Trait::$trait_name"; @@ -51,7 +51,7 @@ Moose::Meta::Attribute::Native - Extend your attribute interfaces ids_in_mapping => 'keys', get_mapping => 'get', set_mapping => 'set', - set_quantity => [ set => [ 'quantity' ] ], + set_quantity => [ set => 'quantity' ], }, ); @@ -60,30 +60,31 @@ Moose::Meta::Attribute::Native - Extend your attribute interfaces 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 attributes provide you with a way to name your accessors, -readers, writers, clearers and predicates, this library provides commonly +While L attributes provide a way to name your accessors, readers, +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, you specify the extension via the -C parameter. Available meta classes are below; see L. +As seen in the L, you specify the data structure via the +C parameter. Available traits are below; see L. This module used to exist as the L 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 extension. +the L extension. L should +continue to work. =head1 PARAMETERS @@ -103,11 +104,11 @@ works normally for C<< handles >>. Common numerical operations. has 'integer' => ( - metaclass => 'Number', + traits => ['Number'], is => 'ro', isa => 'Int', default => 5, - handles => { + handles => { set => 'set', add => 'add', sub => 'sub', @@ -123,11 +124,11 @@ Common numerical operations. Common methods for string operations. has 'text' => ( - metaclass => 'String', + traits => ['String'], is => 'rw', isa => 'Str', default => q{}, - handles => { + handles => { add_text => 'append', replace_text => 'replace', } @@ -138,7 +139,7 @@ Common methods for string operations. Methods for incrementing and decrementing a counter attribute. has 'counter' => ( - traits => ['Counter'], + traits => ['Counter'], is => 'ro', isa => 'Num', default => 0, @@ -154,7 +155,7 @@ Methods for incrementing and decrementing a counter attribute. Common methods for boolean values. has 'is_lit' => ( - traits => ['Bool'], + traits => ['Bool'], is => 'rw', isa => 'Bool', default => 0, @@ -166,7 +167,6 @@ Common methods for boolean values. } ); - =item L Common methods for hash references. @@ -177,9 +177,9 @@ Common methods for hash references. isa => 'HashRef[Str]', default => sub { {} }, handles => { - set_option => 'set', - get_option => 'get', - has_option => 'exists', + set_option => 'set', + get_option => 'get', + has_option => 'exists', } ); @@ -192,12 +192,26 @@ Common methods for array references. is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] }, - handles => { - add_item => 'push' + handles => { + add_item => 'push', next_item => 'shift', } ); +=item L + +Common methods for code references. + + has 'callback' => ( + traits => ['Code'], + is => 'ro', + isa => 'CodeRef', + default => sub { sub { 'called' } }, + handles => { + call => 'execute', + } + ); + =back =head1 BUGS