From: Kent Fredric Date: Wed, 27 Mar 2013 05:55:28 +0000 (+1300) Subject: +t/native_traits/custom_types.t: Add a test for 3rd party defined native types X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4ddb88c41cd010c1fc39207e7c236e61ac95d79a;p=gitmo%2FMoose.git +t/native_traits/custom_types.t: Add a test for 3rd party defined native types --- diff --git a/t/native_traits/custom_types.t b/t/native_traits/custom_types.t new file mode 100644 index 0000000..d9aff61 --- /dev/null +++ b/t/native_traits/custom_types.t @@ -0,0 +1,85 @@ +use strict; +use warnings; + +use Test::More; +use Test::Fatal; + +# ABOUT: +# +# This test tests for unusual use of Native Types, +# specificially, creation of 3rd Party Native types using the Core Native Types infrastructure, +# but without having the definitions of all the accessors under the primary Moose namespace, +# so that the only element needed under the Moose namespace is the registration node. + +BEGIN { + package Moose::Meta::Attribute::Custom::Trait::CustomTrait; + + sub register_implementation { + return 'Test::Trait::CustomTrait'; + } + $INC{'Moose/Meta/Attribute/Custom/Trait.pm'} = 1; +} + +BEGIN { + package Test::Trait::CustomTrait; + + use Moose::Role; + with 'Moose::Meta::Attribute::Native::Trait'; + + sub _native_accessor_method_prefix { 'Test::Trait::CustomTrait::Accessors' }; + sub _helper_type { 'ArrayRef' } + + + no Moose::Role; + $INC{'Test/Trait/CustomTrait.pm'} = 1; +} + +BEGIN { + package Test::Trait::CustomTrait::Accessors::example; + + use Moose::Role; + + with 'Moose::Meta::Method::Accessor::Native::Reader' => { -excludes => [ _maximum_arguments =>, ] }; + + + sub _maximum_arguments { 0 } + sub _return_value { + my $self = shift; + my ($slot_access) = @_; + return '"example"'; + } + + no Moose::Role; + + $INC{'Test/Trait/CustomTrait/Accessors/example.pm'} = 1; +} + +BEGIN { + package Example; + + use Moose; + + has attr => ( + isa => 'ArrayRef', + is => 'rw', + required => 1, + traits => [qw( CustomTrait )], + handles => { + do_example => example =>, + } + ); + __PACKAGE__->meta->make_immutable; +} + +is( exception { + my $instance = Example->new( + attr => [ 'Not Used' ], + ); + + is( $instance->do_example, "example" , "Accessor works" ); +}, undef , 'no failures'); + +done_testing; +1; + +