From: Shawn M Moore Date: Tue, 17 Jun 2008 04:13:20 +0000 (+0000) Subject: Add Moose::Role->unimport so we remove the Moose::Role keywords X-Git-Tag: 0_55~108 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d31f96149834b8c341514a0b212f07b8b2dc5be4;p=gitmo%2FMoose.git Add Moose::Role->unimport so we remove the Moose::Role keywords --- diff --git a/Changes b/Changes index 3434666..d9cf1ba 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for Perl extension Moose +0.51 + * Moose::Role + - add unimport so "no Moose::Role" actually does something + 0.50 Thurs. Jun 11, 2008 - Fixed a version number issue by bumping all modules to 0.50. diff --git a/lib/Moose/Role.pm b/lib/Moose/Role.pm index 37eb300..ef5f044 100644 --- a/lib/Moose/Role.pm +++ b/lib/Moose/Role.pm @@ -182,6 +182,26 @@ use Moose::Util::TypeConstraints; goto $exporter; }; + sub unimport { + no strict 'refs'; + my $class = _get_caller(@_); + + # loop through the exports ... + foreach my $name ( keys %exports ) { + + # if we find one ... + if ( defined &{ $class . '::' . $name } ) { + my $keyword = \&{ $class . '::' . $name }; + + # make sure it is from Moose::Role + my ($pkg_name) = Class::MOP::get_code_info($keyword); + next if $pkg_name ne 'Moose::Role'; + + # and if it is from Moose::Role then undef the slot + delete ${ $class . '::' }{$name}; + } + } + } } 1; @@ -251,6 +271,12 @@ lightly. =back +=head2 B + +Moose::Role offers a way to remove the keywords it exports, through the +C method. You simply have to say C at the bottom of +your code for this to work. + =head1 CAVEATS Role support has only a few caveats: