__PACKAGE__->setup_import_methods(
with_caller => ['parameter', 'role', 'method'],
- as_is => ['has', 'with', 'extends', 'requires', 'excludes', 'augment', 'inner', 'before', 'after', 'around'],
+ as_is => ['has', 'with', 'extends', 'requires', 'excludes', 'augment', 'inner', 'before', 'after', 'around', 'super', 'override'],
);
sub parameter {
$CURRENT_METACLASS->add_excluded_roles(@_);
}
+# see Moose.pm for discussion
+sub super {
+ return unless $Moose::SUPER_BODY;
+ $Moose::SUPER_BODY->(@Moose::SUPER_ARGS);
+}
+
+sub override {
+ confess "override must be called within the role { ... } block."
+ unless $CURRENT_METACLASS;
+
+ my ($name, $code) = @_;
+ $CURRENT_METACLASS->add_override_method_modifier($name, $code);
+}
+
sub extends { croak "Roles do not currently support 'extends'" }
sub inner { croak "Roles cannot support 'inner'" }
--- /dev/null
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 2;
+
+my @calls;
+
+do {
+ package MyRole::LogMethod;
+ use MooseX::Role::Parameterized;
+
+ parameter method => (
+ is => 'rw',
+ isa => 'Str',
+ required => 1,
+ );
+
+ role {
+ my $p = shift;
+
+ override $p->method => sub {
+ push @calls, "calling " . $p->method;
+ super;
+ push @calls, "called " . $p->method;
+ };
+ };
+};
+
+do {
+ package MyClass;
+ use Moose;
+ with 'MyRole::LogMethod' => {
+ method => 'new',
+ };
+};
+
+is_deeply([splice @calls], [], "no calls yet");
+MyClass->new;
+is_deeply([splice @calls], ["calling new", "called new"], "instrumented new");
+