Bread:...dencies(3pm)

πŸ“¦
version 0.37 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing

πŸ’– 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 β€” a Hashref, and it's constrained by Bread::Board::Service::Dependencies. the values in it must be instances of Bread::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 get on 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::Thunk instance. on that thunk you can call the inflate method, 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::Deferred that 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. 🫢


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