Subject: | depends_on('../foo') causes Deep recursion |
I don't think this is a bug, but I do find it counter-intuitive. Consider the following
Bread::Board:
my $c = container 'Star_Wars' => as {
service han_solo => 'Shot First';
container Mos_Eisley => as {
service han_solo => 'Shot Back';
service cantina => (
block => sub {
my $s = shift;
return {
han_solo => $s->param('han_solo'),
};
},
dependencies => {
han_solo => depends_on('../../../han_solo'),
},
);
};
};
my $cantina = $c->resolve( service => 'Mos_Eisley/cantina' );
say "Han Solo $cantina->{han_solo}";
This will print the correct string, "Han Solo Shot First" (which we all know is true). However,
the line:
han_solo => depends_on('../../../han_solo'),
seems counter-intuitive.
I would expect:
han_solo => depends_on('han_solo'),
to give the wrong answer "Han Solo Shot Back" and it does.
I would expect:
han_solo => depends_on('../han_solo'),
to do what I got with ../../../han_solo, but instead we crash altogether:
Deep recursion on subroutine "Bread::Board::Dependency::is_locked" at
.../lib/site_perl/5.12.1/darwin-2level/Moose/Meta/Method/Delegation.pm line 108.
I don't expect ../../han_solo to do anything correctly at all, but:
han_solo => depends_on('../../han_solo'),
Actually yields "Han Solo Shot Back" which is so wrong and also the same as
depends_on('han_solo') which does seem right.
Now, I understand why each of these is happening, because the dependency object gets the
service itself as it's parent. So ../han_solo refers to the dependency, so it is referring back to
itself, which wreaks havoc. This also means that we have to do .. to traverse to the cantina
service, .. to get to the Mos_Eisley container, and .. to get to the Star_wars container to finally
get to a place we can get to the correct han_solo.
This does not match up at all with my expectation since:
depends_on('han_solo') === depends_on('../../han_solo')
I did not expect to be dependencies to be traversed this way. If at all traversable, I would
expect them to be available depends_on('cantina/han_solo') so that the notion would match
up with usual directory traversal (where I've added the notion of "."):
depends_on('.') === depends_on('/Mos_Eisley')
depends_on('..') === depends_on('/')
depends_on('../han_solo') === depends_on('/han_solo')
depends_on('./han_solo') === depends_on('/Mos_Eisley/han_solo') ===
depends_on('han_solo')
depends_on('./cantina') === depends_on('/Mos_Eisley/cantina') === depends_on('cantina')
depends_on('./cantina/han_solo') === depends_on('/Mos_Eisley/cantina/han_solo') ==
depends_on('cantina/han_solo')
Why does it work this way so that 'foo' === '../../foo" within the injector?
I'm assuming, since I have lots of respect for Stevan's designs, that there are good reasons for
this. However, would it be possible to get a "./" prefix or "~/" or something that could be
used as a shortcut that would make up for the deficiency?