The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Bread::Board::Service - Base service role

VERSION

version 0.37

DESCRIPTION

This role is the basis for all services in Bread::Board. It provides (or requires the implementation of) the minimum necessary building blocks: creating an instance, setting/getting parameters, instance lifecycle.

ATTRIBUTES

name

Read/write string, required. Every service needs a name, by which it can be referenced when fetching it.

is_locked

Boolean, defaults to false. Used during dependency resolution to detect loops.

lifecycle

  $service->lifecycle('Singleton');

Read/write string; it should be either a partial class name under the Bread::Board::LifeCycle:: namespace (like Singleton for Bread::Board::LifeCycle::Singleton) or a full class name prefixed with + (like +My::Special::Lifecycle). The name is expected to refer to a loadable role, which will be applied to the service instance.

METHODS

lock

Locks the service; you should never need to call this method in normal code.

unlock

Unlocks the service; you should never need to call this method in normal code.

get

  my $value = $service->get();

This method must be implemented by the consuming class. It's expected to instantiate whatever object or value this service should resolve to.

init_params

Builder for the service parameters, defaults to returning an empty hashref.

clear_params

Clearer of the service parameters.

param

  my @param_names = $service->param();
  my $param_value = $service->param($param_name);
  $service->param($name1=>$value1,$name2=>$value2);

Getter/setter for the service parameters; notice that calling this method with no arguments returns the list of parameter names.

Please note: these are not the same as the parameters for a parametric service (although those will be copied here before get is called), nor are they the same thing as dependencies (although the resolved dependencies will be copied here before get is called).

clone_and_inherit_params

When declaring a service using the service helper function, if the name you use starts with a '+', the service definition will extend an existing service with the given name (without the '+'). This method implements the extension semantics: the dependencies and parameters options will be merged with the existing values, rather than overridden.

AUTHOR

Stevan Little <stevan@iinteractive.com>

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/stevan/BreadBoard/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

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.