Class::Method::ModifiersX::Override - adds "override method => sub {...}" support to Class::Method::Modifiers
use v5.14; use strict; use Test::More; package Foo { sub new { bless []=> shift } sub foo { return "foo" } } package Foo::Bar { BEGIN { our @ISA = 'Foo' } use Class::Method::ModifiersX::Override; override foo => sub { return uc super; }; } is( Foo::Bar->new->foo, "FOO" ); done_testing();
(Note that the synopsis shows Perl v5.14+ syntax for package declaration, but this module and its accompanying Moo and Role::Tiny wrappers support Perl v5.8 and above.)
Class::Method::ModifiersX::Override extends Class::Method::Modifiers with the override
method modifier, allowing you to use this Moose syntactic sugar for overriding superclass methods in non-Moose classes.
See Moose::Manual::MethodModifiers for details of how override
and its companion function super
work.
This module exports two functions:
If you want to use these with Moo classes or role, or with Role::Tiny roles, please look at MooX::Override or Role::TinyX::Override instead.
This implementation of override
piggybacks onto Class::Method::Modifiers' implementation of around
. As a result, when multiple method modifiers are applied to the same method, the order in which they are applied might not match Moose, where override
modifiers are "innermost".
Given that this implementation of override
piggybacks onto around
, there's almost no reason to use it; you can just use around
instead. This module mostly exists as an answer to people who complain that Moo doesn't support override
/super
, but it may also be helpful porting Moose code to Moo.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Class-Method-ModifiersX-Override.
Class::Method::ModifiersX::Override requires Perl 5.008, and the Class::Method::Modifiers package (which is available from CPAN).
The accompanying modules MooX::Override and Role::TinyX::Override require Moo and Role::Tiny respectively. However, the installation scripts for this distribution do not check that these are installed. If you use MooX::Override or Role::TinyX::Override, it is assumed that you have installed their dependencies separately.
Moose::Manual::MethodModifiers, Class::Method::Modifiers, MooX::Override, Role::TinyX::Override.
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.