On Mon, Apr 29, 2013 at 11:18 AM, Chris Prather <ch...@prather.org> wrote:
> On Mon, Apr 29, 2013 at 2:03 PM, Karen Etheridge <p...@froods.org> wrote: > > > Altneratively, you might find the augment/inner method modification > pattern > > to be of use -- a method can always opt to not call inner() if it has had > > its preconditions satisfied already. (Actually, this is probably better > > than my first suggestion.) > > > > > I'm not sure augment/inner is ever the right answer, but it's certainly > better than relying upon Role application order. > In my case the order is not really important -- just need to find the first one that succeeds. Although, in general I could see situation where the order would be important. I'm not following the code below. Do you have an array or roles brought in using "with"? Or instances of classes that all have an authenticate() method? What I'm not understanding is how you are calling the authenticate method in each role. My other thought was a parameterized role where I pass in a list of authentication classes where each has an authenticate method and then call them in a loop as you have below. Thanks, > > In this situation I'd argue that you want an array of Authentication > Objects that all do the same API-style role. > > role_type AuthPlugin => { role => 'MyApp::AuthPlugin' }; > > has auth_plugins => ( isa => 'ArrayRef[AuthPlugin]', traits => ['Array'], > handles => { auth_plugins => 'elements' }); > > sub authenticate { > my $self = shift; > return if $_->authenticate(@_) for $self->auth_plugins; > confess "Authentication Failed" > } > > That way you can add arbitrarily many auth plugins to the list in a > specific order. > -- Bill Moseley mose...@hank.org