Bread:...dencies(3pm)
π Bread::Board::Service::WithDependencies π
okay bestie, welcome to Bread::Board::Service::WithDependencies β a whole entire role in the Bread::Board universe, filed under the User Contributed Perl Documentation section of the manual, page name Bread:...dencies(3pm). yes the name is truncated, it's giving mystery, it's giving ellipsis-core. π
β¨ VERSION β¨
this is version 0.37. noted. logged. slayed. π
πΈ DESCRIPTION πΈ
so basically this is a sub-role of Bread::Board::Service, and it exists for services that have dependencies β like, services that can't just show up to the function alone, they need their friends there too. π«Ά
what does it actually do tho? it gives you the whole mechanism to recursively resolve dependencies. recursively!! it goes and gets the thing that gets the thing that gets the thing. it's giving main character energy with a full entourage. π
π¦ ATTRIBUTES π¦
dependenciesβ aHashref, and it's constrained byBread::Board::Service::Dependencies. the values in it must be instances ofBread::Board::Dependency, but lowkey they can be coerced from various other types too β go read the type's docs for the tea, i'm not gonna spoil it here. β
π METHODS π
add_dependency
$service->add_dependency(name=>$dep);
adds a new dependency. that's it, that's the whole thing. she's simple, she's iconic. β¨
get_dependency
my $dep = $service->get_dependency('name');
gets a dependency, by name. you hand her a name, she hands you the dependency. mutual exchange, very demure. π
has_dependency
if ($service->has_dependency('name')) { ... }
returns true if this service has a dependency with the given name. a lil vibe check, basically. π
has_dependencies
if ($service->has_dependencies) { ... }
returns true if this service has any dependency at all. just one is enough to pass the check. periodt. π
get_all_dependencies
my %deps = $service->get_all_dependencies;
returns all the dependencies for this service, as a key-value list. the whole roster. the full squad. no one left behind. π
init_params
this one is the builder for the service parameters, except it's been augmented β it injects all the resolved dependencies into the params attribute, so that get can actually use them. she's doing the behind-the-scenes labor and honestly? we should thank her. π«Ά
get
so here's the thing: after the get method runs, the params attribute gets cleared β the whole point being to make sure the dependencies will be resolved again on the next call. π
wait, doesn't that mean it redoes the work every time?? okay yes, BUT β if the service is using a singleton lifecycle, the whole "getting" only happens once anyway. so like, chill. it's fine. it's giving efficiency, eventually. π
resolve_dependencies
my %name_object_map = $self->resolve_dependencies;
okay this is the big one, the finale, the main event. π€
for each element of dependencies, it calls its service method to retrieve the service we're dependent on, and then it tries to instantiate the value of that service. and bestie, this can go down in a few different ways:
- the service is not locked, and does not require any parameter β easy mode, we just call
geton it. β¨ - the service is not locked, requires parameters, but the dependency has values for them β we call
$service->get(%{$dependency->service_params}). look at us, we had the values the whole time. π - the service is not locked, requires parameters, and we don't have values for them β okay so we literally can't instantiate anything at this point π, so instead we use a
Bread::Board::Service::Deferred::Thunkinstance. on that thunk you can call theinflatemethod, hand it all the needed parameters, and then you get the actual instance. it's giving "brb gotta go get the rest of myself". π¦ - the service is locked β we return a
Bread::Board::Service::Deferredthat will proxy to the instance that the service will eventually return. and yes, this means that in many cases circular dependencies can be resolved β at the cost of a proxy object. the trade-off is real, the drama is real, but the circular dependency got handled so. worth it. π₯
π AUTHOR π
Stevan Little <stevan@iinteractive.com> β the author, the icon, the moment. π
π BUGS π
please report any bugs or feature requests on the bugtracker website:
https://github.com/stevan/BreadBoard/issues
and when you're submitting a bug or a request, please include a test-file or a patch to an existing test-file that illustrates the bug or the desired feature. like, help us help you, bestie. we can't fix a vibe we can't reproduce. π«Ά
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2019, 2017, 2016, 2015, 2014, 2013, 2011, 2009 by Infinity Interactive.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. πΈ
and that's the whole page, no cap!! π this was perl v5.36.0, dated 2022-12-12, and you were reading Bread:...dencies(3pm) β go forth and resolve your dependencies recursively, queen. mwah. π
β¨π
π¦ where this page comes from
- debian bookworm: libbread-board-perl 0.37-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libbread-board-perl 0.37-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libbread-board-perl 0.37-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: libbread-board-perl 0.37-2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms