MooseX::RoleQR - allow "before qr{...} => sub {...};" in roles
{ package Local::Role; use MooseX::RoleQR; after qr{^gr} => sub { print " World\n"; }; } { package Local::Class; use Moose; with qw( Local::Role ); sub greet { print "Hello"; } } Local::Class->new->greet; # prints "Hello World\n"
Method modifiers in Moose classes can be specified using regular expressions a la:
before qr{...} => sub {...};
However, this is not allowed in Moose roles because Moose doesn't know which class the role will be composed with, and thus doesn't know which method names match the regular expression. Let's change that.
This module implements regular expression matched method modifiers for Moose roles. It does so by deferring the calculation of which methods to modify until role application time.
The current implementation handles only before, after and around modifiers (not override), and thus it overrides the following standard Moose::Role keywords:
before
after
around
override
before Str|ArrayRef|RegexpRef => CodeRef
after Str|ArrayRef|RegexpRef => CodeRef
around Str|ArrayRef|RegexpRef => CodeRef
Moose executes method modifiers in a well-defined order (see Moose::Manual::MethodModifiers for details). This module has the potential to disrupt that order, as regular expression matched modifiers are always applied after the role's other modifiers have been applied.
use Moose::Role
You should use MooseX::RoleQR instead of Moose::Role; not as well as.
use MooseX::RoleQR
There's some pretty nasty stuff under the hood. Let's pretend it's not there.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=MooseX-RoleQR.
Moose::Role.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install MooseX::RoleQR, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::RoleQR
CPAN shell
perl -MCPAN -e shell install MooseX::RoleQR
For more information on module installation, please visit the detailed CPAN module installation guide.