Also see Moose::Manual::Delta for more details of, and workarounds
for, noteworthy changes.
+ [NEW FEATURES]
+
+ * Moose::Meta::Attribute::Native::Trait::Code now provides execute_method, in
+ addition to execute, to be able to call a code attribute as a method.
+ (Florian Ragwitz)
+
[ENHANCEMENTS]
* Moose::Object::does no longer checks the entire inheritance tree, since
our $AUTHORITY = 'cpan:STEVAN';
sub execute : method {
- my ( $attr, $reader, $writer ) = @_;
- return sub { my ($self, @args) = @_; $reader->($self)->(@args) };
+ my ($attr, $reader, $writer) = @_;
+ return sub {
+ my ($self, @args) = @_;
+ $reader->($self)->(@args);
+ };
+}
+
+sub execute_method : method {
+ my ($attr, $reader, $writer) = @_;
+ return sub {
+ my ($self, @args) = @_;
+ $reader->($self)->($self, @args);
+ };
}
no Moose::Role;
Calls the coderef with the given args.
+=item B<execute_method(@args)>
+
+Calls the coderef with the the instance as invocant and given args.
+
=back
=head1 METHODS
use Moose;
has callback => (
- traits => ['Code'],
- is => 'ro',
- isa => 'CodeRef',
+ traits => ['Code'],
+ is => 'ro',
+ isa => 'CodeRef',
+ required => 1,
+ handles => { 'invoke_callback' => 'execute' },
+ );
+
+ has callback_method => (
+ traits => ['Code'],
+ is => 'ro',
+ isa => 'CodeRef',
required => 1,
- handles => { 'invoke_callback' => 'execute' },
+ handles => { 'invoke_method_callback' => 'execute_method' },
);
has multiplier => (
my $i = 0;
my $thingy = Thingy->new(
- callback => sub { ++$i },
- multiplier => sub { $_[0] * 2 }
+ callback => sub { ++$i },
+ multiplier => sub { $_[0] * 2 },
+ callback_method => sub { shift->multiply(@_) },
);
is($i, 0);
$thingy->invoke_callback;
is($i, 1);
is($thingy->multiply(3), 6);
+is($thingy->invoke_method_callback(3), 6);
done_testing;