From: Shawn M Moore Date: Sun, 14 Dec 2008 21:31:00 +0000 (+0000) Subject: Support for parameterized traits in attributes X-Git-Tag: 0.64~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8974015ded994d2fbaf076de0bf29e5a130b1929;p=gitmo%2FMoose.git Support for parameterized traits in attributes --- diff --git a/Changes b/Changes index 227f4be..1f25479 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,8 @@ Revision history for Perl extension Moose 0.64 * Moose::Meta::Method::Accessor - Always inline predicate and clearer methods (Sartak) + * Moose::Meta::Attribute + - Support for parameterized traits (Sartak) 0.63 Mon, December 8, 2008 * Moose::Unsweetened diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 1a47b7b..04e69f8 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -108,10 +108,22 @@ sub interpolate_class { my @traits; if (my $traits = $options{traits}) { - @traits = - grep { not $class->does($_) } - map { Moose::Util::resolve_metatrait_alias(Attribute => $_) || $_ } - @$traits; + my $i = 0; + while ($i < @$traits) { + my $trait = $traits->[$i++]; + next if ref($trait); # options to a trait we discarded + + $trait = Moose::Util::resolve_metatrait_alias(Attribute => $trait) + || $trait; + + next if $class->does($trait); + + push @traits, $trait; + + # are there options? + push @traits, $traits->[$i++] + if $traits->[$i] && ref($traits->[$i]); + } if (@traits) { my $anon_class = Moose::Meta::Class->create_anon_class(