Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot have optional parameters #51

Closed
vlad-ghita opened this issue Jul 4, 2016 · 2 comments
Closed

Cannot have optional parameters #51

vlad-ghita opened this issue Jul 4, 2016 · 2 comments

Comments

@vlad-ghita
Copy link

I have this setup:

package Foo;
use Moo;

has p1 => ( is => 'rw' );
has p2 => ( is => 'rw' );
has p3 => ( is => 'rw' );
has p4 => ( is => 'rw' );

package main;

my $c = container 'container' => as {
    service 'foo' => (
        class => 'Foo',
        parameters => {
            p1 => { required => 1 },
            p2 => { required => 0 },
            p3 => { },
            p4 => { },
        }
    );
};

my $foo = $c->resolve(service => 'foo', parameters => { p4 => 'test' });

I get this error:

Mandatory parameters 'p1', 'p2', 'p3' missing in call to Bread::Board::Service::WithParameters::check_parameters.

Why is p2 required? It has required => 0.

@vlad-ghita
Copy link
Author

Fixed it ... Must used optional => 1

my $c = container 'container' => as {
    service 'foo' => (
        class => 'Foo',
        parameters => {
            p1 => { required => 1 },
            p2 => { optional => 1 },
            p3 => { },
            p4 => { },
        }
    );
};

@yanick
Copy link
Collaborator

yanick commented Jul 4, 2016

Yeah, the parameters are groomed bu MooseX::Params::Validate, and that module will treat all parameters as required unless optional or default is present (it's documented in B::B::Service::WithParameters).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants