X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FAttribute%2FNative%2FTrait.pm;h=f03f509e943cab42c6d2995bc72f20b5a037ddee;hb=rfc%2Fkentnl%2Fnative_traits_flex;hp=b0065466f8ebd84ac927a2089896a2556178b60c;hpb=4ddb88c41cd010c1fc39207e7c236e61ac95d79a;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Attribute/Native/Trait.pm b/lib/Moose/Meta/Attribute/Native/Trait.pm index b006546..f03f509 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait.pm @@ -169,13 +169,29 @@ sub _root_types { return $_[0]->_helper_type; } + +# +# Foo::Bar::Baz::Quux::doo +# +# ^^^^^^^^^^^^^ - native accessor type prefix +# ^^^^^^^^^^^^^^^^^^^ - native accessor method prefix +# ^^^^^^^^^^^^^^^^^^^^^^^^ - native accessor methodclass for ( $suffix = doo ) + +sub _native_accessor_type_prefix { 'Moose::Meta::Method::Accessor::Native' } + +sub _native_accessor_method_prefix { + my ( $self, ) = @_; + return $self->_native_accessor_type_prefix . '::' . $self->_native_type ; +} +sub _native_accessor_methodclass_for { + my ( $self, $suffix ) = @_; + return $self->_native_accessor_method_prefix . '::' . $suffix; +} + sub _native_accessor_class_for { my ( $self, $suffix ) = @_; - my $role - = 'Moose::Meta::Method::Accessor::Native::' - . $self->_native_type . '::' - . $suffix; + my $role = $self->_native_accessor_methodclass_for( $suffix ); load_class($role); return Moose::Meta::Class->create_anon_class( @@ -186,11 +202,15 @@ sub _native_accessor_class_for { )->name; } +sub _native_type_matcher { qr/::Native::Trait::(\w+)$/ } + sub _build_native_type { my $self = shift; + my $matcher = $self->_native_type_matcher; for my $role_name ( map { $_->name } $self->meta->calculate_all_roles ) { - return $1 if $role_name =~ /::Native::Trait::(\w+)$/; + + return $1 if $role_name =~ $matcher } die "Cannot calculate native type for " . ref $self;