subclassing Bread::Board::Service to replace _filter_component
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Service / WithContext.pm
1 package Catalyst::Service::WithContext;
2 use Moose::Role;
3
4 use Bread::Board::Types;
5
6 with 'Bread::Board::Service';
7
8 has accept_context_sub => (
9     is => 'ro',
10     isa => 'Str',
11     default => 'ACCEPT_CONTEXT',
12 );
13
14 around 'get' => sub {
15     my ( $orig, $self, @params ) = @_;
16
17     my $instance = $self->$orig();
18     my $ac_sub   = $self->accept_context_sub;
19
20     if ( $instance->can($ac_sub) ) {
21         return $instance->$ac_sub( @params );
22     }
23
24     return $instance;
25 };
26
27 no Moose::Role;
28 1;