From: Dave Rolsky Date: Sat, 26 Feb 2011 18:44:44 +0000 (-0600) Subject: Use applied_attribute metarole with Moose 1.9900+ X-Git-Tag: v0.09~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8a1964e9ff0241b5b0247821b1eedb12b6b0478e;p=gitmo%2FMooseX-SemiAffordanceAccessor.git Use applied_attribute metarole with Moose 1.9900+ --- diff --git a/lib/MooseX/SemiAffordanceAccessor.pm b/lib/MooseX/SemiAffordanceAccessor.pm index f1a5834..baae5d5 100644 --- a/lib/MooseX/SemiAffordanceAccessor.pm +++ b/lib/MooseX/SemiAffordanceAccessor.pm @@ -8,7 +8,7 @@ use Moose::Exporter; use Moose::Util::MetaRole; use MooseX::SemiAffordanceAccessor::Role::Attribute; -Moose::Exporter->setup_import_methods( +my %metaroles = ( class_metaroles => { attribute => ['MooseX::SemiAffordanceAccessor::Role::Attribute'], }, @@ -17,6 +17,12 @@ Moose::Exporter->setup_import_methods( }, ); +$metaroles{role_metaroles} = { + applied_attribute => ['MooseX::SemiAffordanceAccessor::Role::Attribute'], +} if $Moose::VERSION >= 1.9900; + +Moose::Exporter->setup_import_methods(%metaroles); + 1; # ABSTRACT: Name your accessors foo() and set_foo() diff --git a/t/role.t b/t/role.t new file mode 100644 index 0000000..ffb5de0 --- /dev/null +++ b/t/role.t @@ -0,0 +1,39 @@ +use strict; +use warnings; + +use Test::More; + +use Moose (); + +plan skip_all => 'This test requires Moose 1.9900+' + unless $Moose::VERSION ge '1.9900'; + +{ + package Role::SAA; + + use Moose::Role; + use MooseX::SemiAffordanceAccessor; + + has 'foo' => ( is => 'rw' ); + has '_bar' => ( is => 'rw' ); +} + +{ + package Class; + + use Moose; + + with 'Role::SAA'; + + has 'thing' => ( is => 'rw' ); + has '_private' => ( is => 'rw' ); +} + +can_ok( 'Class', 'thing' ); +ok( ! Class->can('set_thing') ); +can_ok( 'Class', '_private' ); +ok( ! Class->can('_set_private') ); + +can_ok( 'Class', qw( foo set_foo _bar _set_bar ) ); + +done_testing();