Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7747439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:31:45+00:00 2026-06-01T10:31:45+00:00

I found myself instantiating the same objects in numerous tests, so I’m trying to

  • 0

I found myself instantiating the same objects in numerous tests, so I’m trying to replace this constant setup by using Bread::Board. Most of the time I will want the dependencies to have the same configuration. But occasionally I may want to have an instance created with parameters that are not the default. I’d also like to be able to change this after I’ve created an instance of the container. e.g. I’d normally want

my $c = Test::Container->new;

my $bar = $c->resolve( service => 'bar' ); # where bar depends on foo

but sometimes what I really need is something like

my $bar = $c->resolve( service => 'bar', {
              services => {
                foo => { init => 'arg' }
              }
          }

so that service foo is initialized differently while creating the instance of bar.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:31:46+00:00Added an answer on June 1, 2026 at 10:31 am

    This was provided to me by Jesse Luehrs (Doy) on #moose and appears that it’ll do what I want.

    #!/usr/bin/env perl
    use v5.14;
    use strict;
    use warnings;
    
    package Container {
    use Moose;
    use Bread::Board;
    
    extends 'Bread::Board::Container';
    
    has '+name' => (default => 'Container');
    
    sub BUILD {
        my $self = shift;
        container $self => as {
            service foo => (
                block => sub {
                    my $s = shift;
                    $s->param('foo_val');
                },
                parameters => {
                    foo_val => { isa => 'Str' },
                },
            );
            service bar => (
                block => sub {
                    my $s = shift;
                    $s->param('foo')->inflate(foo_val => $s->param('foo_val')) . 'BAR';
                },
                dependencies => ['foo'],
                parameters => {
                    foo_val => { isa => 'Str', default => 'FOO' },
                },
            );
        };
    }
    }
    
    my $c = Container->new;
    warn $c->resolve(service => 'bar');
    warn $c->resolve(service => 'bar', parameters => { foo_val => 'baz' });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Found myself trying to find a link to an official definition of this design
I found myself using this: $var=(string)array_shift(array_values($item->xpath($s))); where $s is an xpath search string and
I recently found myself using the same pattern over and over in my code.
Found myself quite confused today about this. I create a blank repository locally(hg init),
Lately I found myself using jQuery and JavaScript a lot, often to do the
I have found myself writing the same view over and over. It is basically
I found myself repeat on the same structure over and over again in all
I found myself passing InputStream/OutputStream objects around my application modules. I'm wondering if it's
I found myself keep writing pretty long one-liner code(influenced by shell pipe), like this:
I found myself reading the same questions over and over, so I wanted a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.