From: gfx Date: Mon, 26 Jul 2010 10:41:44 +0000 (+0900) Subject: Add $attr->insertion_order X-Git-Tag: 0.64~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=beb51b30c36db012d0e8c7fdca87e44213ca81f5;p=gitmo%2FMouse.git Add $attr->insertion_order --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index af204d8..6d8bb3a 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -16,6 +16,7 @@ my %valid_options = map { $_ => undef } ( 'does', 'handles', 'init_arg', + 'insertion_order', 'is', 'isa', 'lazy', @@ -37,7 +38,6 @@ my %valid_options = map { $_ => undef } ( # Moose defines, but Mouse doesn't #'definition_context', #'initializer', - #'insertion_order', # special case for AttributeHelpers 'provides', diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index 7963f78..a21c83d 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -209,6 +209,7 @@ sub add_attribute { weaken( $attr->{associated_class} = $self ); + $attr->{insertion_order} = keys %{ $self->{attributes} }; $self->{attributes}{$attr->name} = $attr; $attr->install_accessors(); diff --git a/lib/Mouse/PurePerl.pm b/lib/Mouse/PurePerl.pm index 535ec98..8c9ad86 100644 --- a/lib/Mouse/PurePerl.pm +++ b/lib/Mouse/PurePerl.pm @@ -482,6 +482,7 @@ sub should_auto_deref { $_[0]->{auto_deref} } sub should_coerce { $_[0]->{coerce} } sub documentation { $_[0]->{documentation} } +sub insertion_order { $_[0]->{insertion_order} } # predicates diff --git a/t/001_mouse/007-attributes.t b/t/001_mouse/007-attributes.t index 39667c1..f4c60ee 100644 --- a/t/001_mouse/007-attributes.t +++ b/t/001_mouse/007-attributes.t @@ -76,4 +76,8 @@ dies_ok { Class->write_attr(42); }; +my @attrs = map { $_->name } + sort { $a->insertion_order <=> $b->insertion_order } $object->meta->get_all_attributes; +is join(' ', @attrs), 'x y z attr', 'insertion_order'; + done_testing; diff --git a/xs-src/MouseAttribute.xs b/xs-src/MouseAttribute.xs index 617a99a..6958375 100644 --- a/xs-src/MouseAttribute.xs +++ b/xs-src/MouseAttribute.xs @@ -249,6 +249,7 @@ BOOT: INSTALL_SIMPLE_READER_WITH_KEY(Attribute, should_auto_deref, auto_deref); INSTALL_SIMPLE_READER_WITH_KEY(Attribute, should_coerce, coerce); INSTALL_SIMPLE_READER(Attribute, documentation); + INSTALL_SIMPLE_READER(Attribute, insertion_order); /* predicates */ INSTALL_SIMPLE_PREDICATE_WITH_KEY(Attribute, has_accessor, accessor);