Bread:...ameters(3pm)

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

πŸ’– Bread:...ameters(3pm) β€” User Contributed Perl Documentation πŸ’–

okay bestie, welcome to the manual page for Bread::Board::Service::WithParameters, served up fresh from the User Contributed Perl Documentation collection, section 3pm. pull up a chair, grab a boba, we're doing parameterized services today and it's gonna be iconic πŸ§‹βœ¨


🌸 NAME 🌸

Bread::Board::Service::WithParameters β€” services with parameters, periodt.


πŸŽ€ VERSION πŸŽ€

version 0.37 πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so this is a sub-role of Bread::Board::Service, and it exists specifically for parameterized services. what's that mean? it means these services will instantiate different values depending on parameters that get passed to the get method. it's giving ✨customization✨

and how do you actually pass those parameters in? two ways, bestie:

  • through the service_params attribute of Bread::Board::Dependency
  • or through the inflate method of Bread::Board::Service::Deferred::Thunk

pick your fighter, they both slay πŸ’…


✨ ATTRIBUTES ✨

πŸ‘‘ parameters

read-only hashref, and it gets passed as-is straight into MooseX::Params::Validate's validated_hash. which is huge, because it means you get to use things like optional and default on top of your regular type constraints. no cap.

like, check this out:

service something => (
  class => 'Thing',
  parameters => {
     type => { isa => 'Str', default => 'text' },
  },
);

okay but here's the cute part πŸŽ€ β€” this attribute uses coercions on Bread::Board::Service::Parameters, so you can ALSO just say:

service something => (
  class => 'Thing',
  parameters => ['type'],
);

and bestie, that is equivalent to:

service something => (
  class => 'Thing',
  parameters => {
     type => { optional => 0 },
  },
);

same energy, way less typing. the way that works… we love efficiency πŸ’…


πŸ’œ METHODS πŸ’œ

has_parameters

predicate for the parameters attribute. classic predicate behaviour, nothing spicy.

has_parameter_defaults

returns true if any of the parameters have a default value. that's it, that's the method ✨

has_required_parameters

returns true if any of the parameters does not have optional set to true. so if even one of them is mandatory, this goes true. main character parameter energy fr fr πŸ‘‘

check_parameters

my %parameters = $service->check_parameters(name1=>$value1,name2=>$value2);
my %parameters = $service->check_parameters({name1=>$value1,name2=>$value2});

if any parameters are defined, this function validates its arguments against the parameters' definitions (using MooseX::Params::Validate). and then:

⚠️ it will die if the validation fails πŸ’€ no coming back from that one.

but if it succeeds? it returns the validated parameters β€” including default values β€” and everything is fine and beautiful 🌈

get

okay so before the get method runs, the arguments going into get get passed through check_parameters and then added to the params hashref. and after the get method runs, those keys/values get removed again. clean up after yourself, we stan a tidy queen πŸ’…

in practice? this makes all parameters available to the actual get method body. so your get body just… has them. iconic behaviour, honestly.


🫢 AUTHOR 🫢

Stevan Little <stevan@iinteractive.com>


😭 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, bestie, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. it's giving help us help you πŸ™ˆβœ¨


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. slay, open source πŸ’–


and that's the whole page, bestie!! πŸŽ€ this one was rendered by perl v5.36.0 on 2022-12-12, and yeah the title line got truncated to Bread:...ameters(3pm) because apparently even manpages have a character limit πŸ’€ go forth and parameterize responsibly πŸ¦‹βœ¨

πŸ“¦ where this page comes from