Perl moose triggers in subclasses violate modifier methods

I found that if a subclass adds a trigger, then the modifiers of the method from the base class do not start. This seems to be a Fly's mistake, or at least unintuitive. Here is my example:

package Foo {
    use Moose;

    has 'foo' => (
        is  => 'rw',
        isa => 'Str',
    );

    before 'foo' => sub {
        warn "before foo";
    };
};

package FooChild {

    use Moose;
    extends 'Foo';

    has '+foo' => ( trigger => \&my_trigger, );

    sub my_trigger {
        warn 'this is my_trigger';
    }
};

my $fc = FooChild->new();
$fc->foo(10);

If you run this example, only the warning "this my_trigger" is triggered, and the "before" modifier is ignored. I am using Perl 5.14.2 with Moose 2.0402.

Is this the right behavior? This does not seem correct, especially since the trigger fires after the trigger is defined directly in the base class.

+5
source share
1 answer

By the principle that you should not distinguish between legacy code and code in a class, I would call it an error.

, , , . .

package Foo {
    use Moose;

    has 'foo' => (
        is  => 'rw',
        isa => 'Str',
        default => 5,
    );

    before 'foo' => sub {
        warn "before foo";
    };
};

package FooChild {

    use Moose;
    extends 'Foo';

    has '+foo' => ( default => 99 );
};

my $fc = FooChild->new();
print $fc->foo;

.

+4

All Articles