Skip to content

Commit

Permalink
Fix warning when attribute for delegation does not have definition co…
Browse files Browse the repository at this point in the history
…ntext
  • Loading branch information
autarch committed Jan 30, 2017
1 parent 48075fd commit 85d9460
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ for, noteworthy changes.

{{$NEXT}}

[BUG FIXES]

- Creating a Moose subclass of a Moo class with an attribute with a
delegation would cause a warning.

2.2001 2017-01-29

[TESTS]
Expand Down
1 change: 1 addition & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ IO::String = 0
Locale::US = 0
Module::CPANTS::Analyse = 0.92
Module::Refresh = 0
Moo = 0
MooseX::MarkAsMethods = 0
MooseX::NonMoose = 0
PadWalker = 0
Expand Down
12 changes: 9 additions & 3 deletions lib/Moose/Meta/Method/Delegation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,19 @@ sub {
}
EOF

my $definition = $attr->definition_context;
my $description
= 'inline delegation in '
. $self->package_name . ' for '
. $attr->name . '->'
. $delegate
. " (attribute declared in $definition->{file} at line $definition->{line})";
. $delegate;

my $definition = $attr->definition_context;
# While all attributes created in the usual way (via Moose's has()) will
# define this, there's no guarantee that this must be defined. For
# example, when Moo inflates a class to Moose it does not define these (as
# of Moo 2.003).
$description .= " (attribute declared in $definition->{file} at line $definition->{line})"
if defined $definition->{file} && defined $definition->{line};

return try {
$self->_compile_code(
Expand Down
31 changes: 31 additions & 0 deletions t/bugs/moo_delegation.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use strict;
use warnings;
use Test::More;

use Test::Requires 'Moo', 'Test::Warnings';
use Test::Warnings qw( warnings :no_end_test );

{
package Foo;

use Moo;

has foo => (
is => 'ro',
handles => ['bar'],
);
}

{
package Bar;

use Moose;

::is_deeply(
[ ::warnings { extends 'Foo' } ],
[],
'no warnings when extending Moo class that has a delegation'
);
}

done_testing();

0 comments on commit 85d9460

Please sign in to comment.