Given the following:
- Moo 2.001001;
- Bread::Board 0.34;
- a
Bread::Board
container - base class
Foo
with propertystr
andaround
modifier forstr
- subclass
Bar
extendingFoo
The issue:
- [GOOD] when instantiating object from plain
Bar
,Foo::str
modifier is executed; - [BAD] when instantiating object from container service for
Bar
,Foo::str
modifier is not executed; - [WORSE] after [BAD] happens, instantiating from plain
Bar
no longer works either;
Code example:
#!/usr/qlc/apps/common/perl_5.18.2/bin/perl -w
package Foo;
use Moo;
has str => ( is => 'rw', default => '' );
sub BUILD {
my ($self, $args) = @_;
$self->str($self->str);
}
around str => sub {
my ($orig, $self, $val) = @_;
return $self->$orig unless defined $val;
$self->$orig('prefix_'.$val);
};
# end of Foo
package Bar;
use Moo;
extends 'Foo';
# end of Bar
package main;
use 5.010;
use strictures 2;
use Bread::Board;
my $c = container 'MyApp' => as {
service 'foo' => ( class => 'Foo', parameters => { str => { optional => 1 } } );
service 'bar' => ( class => 'Bar', parameters => { str => { optional => 1 } } );
};
my $foo_plain = Foo->new({ str => 'foo_plain' });
say "foo_plain = ".$foo_plain->str;
my $foo_bb = $c->resolve( service => 'foo', parameters => { str => 'foo_bb' } );
say "foo_bb = ".$foo_bb->str;
$foo_bb->str('foo_bb_setter');
say "foo_bb_setter = ".$foo_bb->str;
my $foo_plain_after_bb = Foo->new({ str => 'foo_plain_after_bb' });
say "foo_plain_after_bb = ".$foo_plain_after_bb->str;
my $bar_plain = Bar->new({ str => 'bar_plain' });
say "bar_plain = ".$bar_plain->str;
my $bar_bb = $c->resolve( service => 'bar', parameters => { str => 'bar_bb' } );
say "bar_bb = ".$bar_bb->str;
$bar_bb->str('bar_bb_setter');
say "bar_bb_setter = ".$bar_bb->str;
my $bar_plain_after_bb = Bar->new({ str => 'bar_plain_after_bb' });
say "bar_plain_after_bb = ".$bar_plain_after_bb->str;
die;
Output:
foo_plain = prefix_foo_plain
foo_bb = prefix_foo_bb
foo_bb_setter = prefix_foo_bb_setter
foo_plain_after_bb = prefix_foo_plain_after_bb
bar_plain = prefix_bar_plain
bar_bb = bar_bb
bar_bb_setter = bar_bb_setter
bar_plain_after_bb = bar_plain_after_bb
Please note outputs bar_bb
, bar_bb_setter
and bar_plain_after_bb
do not contain prefix_
string.
Why?
It was a bug in Bread::Board.
Fixed in this commit.
Thanks @Yanick.