X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FRole.pm;h=956ab99f1e5fc989d1e60099a60809e6d34d63b7;hb=78dc5ed14c0d04c8b73dc8ec701704d72b68e32c;hp=4f02065195fa364e6477f5fae69fc3939cc42971;hpb=2cb8b71324c7f194f869b2633b2fd7be1e669c60;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Role.pm b/lib/Mouse/Role.pm index 4f02065..956ab99 100644 --- a/lib/Mouse/Role.pm +++ b/lib/Mouse/Role.pm @@ -1,15 +1,16 @@ package Mouse::Role; use strict; use warnings; -use base 'Exporter'; + +use Exporter; use Carp 'confess'; use Scalar::Util 'blessed'; -use Mouse::Util qw(load_class not_supported); +use Mouse::Util qw(load_class get_code_package not_supported); use Mouse (); -our @EXPORT = qw(before after around super override inner augment has extends with requires excludes confess blessed); +our @ISA = qw(Exporter); our @EXPORT = qw( extends with @@ -56,29 +57,13 @@ sub around { sub super { - return unless $Mouse::SUPER_BODY; + return if !defined $Mouse::SUPER_BODY; $Mouse::SUPER_BODY->(@Mouse::SUPER_ARGS); } sub override { - my $classname = caller; - my $meta = Mouse::Meta::Role->initialize($classname); - - my $name = shift; - my $code = shift; - my $fullname = "${classname}::${name}"; - - defined &$fullname - && $meta->throw_error("Cannot add an override of method '$fullname' " - . "because there is a local version of '$fullname'"); - - $meta->add_override_method_modifier($name => sub { - local $Mouse::SUPER_PACKAGE = shift; - local $Mouse::SUPER_BODY = shift; - local @Mouse::SUPER_ARGS = @_; - - $code->(@_); - }); + # my($name, $code) = @_; + Mouse::Meta::Role->initialize(scalar caller)->add_override_method_modifier(@_); } # We keep the same errors messages as Moose::Role emits, here. @@ -92,11 +77,9 @@ sub augment { sub has { my $meta = Mouse::Meta::Role->initialize(scalar caller); - my $name = shift; - my %opts = @_; - $meta->add_attribute($name => \%opts); + $meta->add_attribute($_ => @_) for ref($name) ? @{$name} : $name; } sub extends { @@ -151,7 +134,7 @@ sub unimport { my $code; if(exists $is_removable{$keyword} && ($code = $caller->can($keyword)) - && (Mouse::Util::get_code_info($code))[0] eq __PACKAGE__){ + && get_code_package($code) eq __PACKAGE__){ delete $stash->{$keyword}; } @@ -165,59 +148,60 @@ __END__ =head1 NAME -Mouse::Role - define a role in Mouse +Mouse::Role - The Mouse Role + +=head1 SYNOPSIS + + package MyRole; + use Mouse::Role; =head1 KEYWORDS -=head2 meta -> Mouse::Meta::Role +=head2 C<< meta -> Mouse::Meta::Role >> Returns this role's metaclass instance. -=head2 before (method|methods) => Code +=head2 C<< before (method|methods) -> CodeRef >> -Sets up a "before" method modifier. See L or +Sets up a B method modifier. See L or L. -=head2 after (method|methods) => Code +=head2 C<< after (method|methods) => CodeRef >> -Sets up an "after" method modifier. See L or +Sets up an B method modifier. See L or L. -=head2 around (method|methods) => Code +=head2 C<< around (method|methods) => CodeRef >> -Sets up an "around" method modifier. See L or +Sets up an B method modifier. See L or L. -=over 4 - -=item B +=head2 C -Sets up the "super" keyword. See L. +Sets up the B keyword. See L. -=item B +=head2 C<< override method => CodeRef >> -Sets up an "override" method modifier. See L. +Sets up an B method modifier. See L. -=item B +=head2 C -This is not supported and emits an error. See L. +This is not supported in roles and emits an error. See L. -=item B +=head2 C<< augment method => CodeRef >> -This is not supported and emits an error. See L. +This is not supported in roles and emits an error. See L. -=back - -=head2 has (name|names) => parameters +=head2 C<< has (name|names) => parameters >> Sets up an attribute (or if passed an arrayref of names, multiple attributes) to this role. See L. -=head2 confess error -> BOOM +=head2 C<< confess(error) -> BOOM >> L for your convenience. -=head2 blessed value -> ClassName | undef +=head2 C<< blessed(value) -> ClassName | undef >> L for your convenience. @@ -229,8 +213,12 @@ Importing Mouse::Role will give you sugar. =head2 unimport -Please unimport Mouse (C) so that if someone calls one of the +Please unimport (C<< no Mouse::Role >>) so that if someone calls one of the keywords (such as L) it will break loudly instead breaking subtly. +=head1 SEE ALSO + +L + =cut