X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FRole.pm;h=efd7f951d59a2cb76e034507f3aa1175534ff040;hb=6719984210754e8d012ae678536f194c35000823;hp=b57169d6adecb7e93dd27799df354d873b0c5213;hpb=137498b87c4d1b584b500a0a2ef651f8ccd42ee5;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Role.pm b/lib/Mouse/Role.pm index b57169d..efd7f95 100644 --- a/lib/Mouse/Role.pm +++ b/lib/Mouse/Role.pm @@ -3,12 +3,12 @@ use strict; use warnings; use base 'Exporter'; -use Carp 'confess'; +use Carp 'confess', 'croak'; use Scalar::Util 'blessed'; use Mouse::Meta::Role; -our @EXPORT = qw(before after around has extends with requires excludes confess blessed); +our @EXPORT = qw(before after around super override inner augment has extends with requires excludes confess blessed); sub before { my $meta = Mouse::Meta::Role->initialize(caller); @@ -37,6 +37,42 @@ sub around { } } + +sub super { + return unless $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 + && confess "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->(@_); + }); +} + +# We keep the same errors messages as Moose::Role emits, here. +sub inner { + croak "Moose::Role cannot support 'inner'"; +} + +sub augment { + croak "Moose::Role cannot support 'augment'"; +} + sub has { my $meta = Mouse::Meta::Role->initialize(caller); @@ -127,6 +163,22 @@ L. Sets up an "around" method modifier. See L or L. +=item B + +Sets up the "super" keyword. See L. + +=item B + +Sets up an "override" method modifier. See L. + +=item B + +This is not supported and emits an error. See L. + +=item B + +This is not supported and emits an error. See L. + =head2 has (name|names) => parameters Sets up an attribute (or if passed an arrayref of names, multiple attributes) to