From: Shawn M Moore Date: Sun, 28 Sep 2008 02:49:22 +0000 (+0000) Subject: Drop Sub::Exporter from Mouse::Role X-Git-Tag: 0.19~219 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b32e8fb9860b5e46b8409f603a34c76f9465e644;p=gitmo%2FMouse.git Drop Sub::Exporter from Mouse::Role --- diff --git a/lib/Mouse/Role.pm b/lib/Mouse/Role.pm index 14ba27a..99170c2 100644 --- a/lib/Mouse/Role.pm +++ b/lib/Mouse/Role.pm @@ -2,105 +2,81 @@ package Mouse::Role; use strict; use warnings; +use base 'Exporter'; -use Sub::Exporter; use Carp 'confess'; -use Scalar::Util; +use Scalar::Util 'blessed'; use Mouse::Meta::Role; -do { - my $CALLER; - - my %exports = ( - meta => sub { - my $meta = Mouse::Meta::Role->initialize($CALLER); - return sub { $meta }; - }, - extends => sub { - return sub { - confess "Role does not currently support 'extends'"; - } - }, - before => sub { - my $caller = $CALLER; - return sub { - my $code = pop; - for (@_) { - $caller->meta->add_before_method_modifier($_ => $code); - } - } - }, - after => sub { - my $caller = $CALLER; - return sub { - my $code = pop; - for (@_) { - $caller->meta->add_after_method_modifier($_ => $code); - } - } - }, - around => sub { - my $caller = $CALLER; - return sub { - my $code = pop; - for (@_) { - $caller->meta->add_around_method_modifier($_ => $code); - } - } - }, - has => sub { - my $caller = $CALLER; - return sub { - my $name = shift; - my %opts = @_; - - $caller->meta->add_attribute($name => \%opts); - } - }, - with => sub { - return sub { - confess "Role does not currently support 'with'"; - } - }, - requires => sub { - return sub { } - }, - excludes => sub { - return sub { } - }, - blessed => sub { - return \&Scalar::Util::blessed; - }, - confess => sub { - return \&Carp::confess; - }, - ); - - my $exporter = Sub::Exporter::build_exporter({ - exports => \%exports, - groups => { default => [':all'] }, - }); - - sub import { - $CALLER = caller; - - strict->import; - warnings->import; - - goto $exporter; +our @EXPORT = qw(before after around has extends with requires excludes confess blessed); + +sub before { + my $meta = Mouse::Meta::Role->initialize(caller); + + my $code = pop; + for (@_) { + $meta->add_before_method_modifier($_ => $code); + } +} + +sub after { + my $meta = Mouse::Meta::Role->initialize(caller); + + my $code = pop; + for (@_) { + $meta->add_after_method_modifier($_ => $code); } +} + +sub around { + my $meta = Mouse::Meta::Role->initialize(caller); + + my $code = pop; + for (@_) { + $meta->add_around_method_modifier($_ => $code); + } +} + +sub has { + my $meta = Mouse::Meta::Role->initialize(caller); + + my $name = shift; + my %opts = @_; + + $meta->add_attribute($name => \%opts); +} + +sub extends { confess "Roles do not support 'extends'" } + +sub with { confess "Mouse::Role does not currently support 'with'" } + +sub requires {} + +sub excludes {} + +sub import { + strict->import; + warnings->import; + + my $caller = caller; + my $meta = Mouse::Meta::Role->initialize(caller); + + no strict 'refs'; + no warnings 'redefine'; + *{$caller.'::meta'} = sub { $meta }; + + Mouse::Role->export_to_level(1, @_); +} - sub unimport { - my $caller = caller; +sub unimport { + my $caller = caller; - no strict 'refs'; - for my $keyword (keys %exports) { - next if $keyword eq 'meta'; # we don't delete this one - delete ${ $caller . '::' }{$keyword}; - } + no strict 'refs'; + for my $keyword (@EXPORT) { + delete ${ $caller . '::' }{$keyword}; } -}; +} 1; diff --git a/t/400-define-role.t b/t/400-define-role.t index d5e9143..e5d9891 100644 --- a/t/400-define-role.t +++ b/t/400-define-role.t @@ -18,7 +18,7 @@ throws_ok { extends 'Role::Parent'; no Mouse::Role; -} qr/Role does not currently support 'extends'/; +} qr/Roles do not support 'extends'/; lives_ok { package Role;