The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Bread::Board::Svc - shortcuts for Bread::Board::service function

VERSION

version 0.02

SYNOPSIS

    use Bread::Board::Svc qw(svc svc_singleton);

    # instead of 
    service router => (
        class        => 'Router::Pygmy',
        dependencies => ['routes'],
    );

    # you can write positionally
    svc 'router', 'Router::Pygmy', ['routes'];

    # instead of
    service app_data => (
        dependencies => ['app_home'],
        block        => sub {
            my $s = shift;
            my $p = $s->params;
            dir( $p->{app_home}, 'var' );
        }
    );

    # you can write
    svc app_data => ( \['app_home'], sub { dir( shift(), 'var' ) } );

    # or
    svc 'app_data', \['app_home'], sub { dir( shift(), 'var' ) };

DESCRIPTION

This module provides shortcut for Bread::Board::Service with positional params.

EXPORTED FUNCTIONS

All functions are exported on demand.

svc($name, @args)

Creates service by calling Bread::Board::service internally.

svc_singleton($name, @args)

Same as svc but adds lifecycle => 'Singleton' to Bread::Board::service params.

The argument combinations are:

svc($name, $class, $deps, $body)
svc($name, $class, $deps)
svc($name, $deps, $body)
svc($name, $value)

This combination just passes args to Bread::Board::service.

When the service is about to be resolved, then $body subroutine is called. The arguments are $class (if present) and the list of resolved dependencies.

If $deps is a hashref or an arrayref, it has same meaning as for dependencies and resolved dependencies are passed as << $key => $value >>. If $deps is a reference to an arrayref (\ [ $path1, $path2, ... ] ), then only the dependency values are passed to block, without the names (the names are constructed artificially).

If $body is ommitted then the constructor of $class is called (see Bread::Board::ConstructorInjection).

It should be noted that $class is loaded lazily (before first resolution).

AUTHOR

Roman Daniel <roman@daniel.cz>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Roman Daniel.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.