4559a691624eb88bdbeff14189c73e5404aded91
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / Service / WithAcceptContext.pm
1 package Catalyst::IOC::Service::WithAcceptContext;
2 use Moose::Role;
3
4 with 'Bread::Board::Service';
5
6 has accept_context_sub => (
7     is => 'ro',
8     isa => 'Str',
9     default => 'ACCEPT_CONTEXT',
10 );
11
12 around 'get' => sub {
13     my $orig = shift;
14     my $self = shift;
15
16     my $instance = $self->$orig(@_);
17
18     my $accept_context_args = $self->param('accept_context_args');
19     my $ac_sub = $self->accept_context_sub;
20
21     if ( $instance->can($ac_sub) ) {
22         return $instance->$ac_sub( @$accept_context_args );
23     }
24
25     return $instance;
26 };
27
28 no Moose::Role;
29 1;
30
31 __END__
32
33 =pod
34
35 =head1 NAME
36
37 Catalyst::IOC::Service::WithAcceptContext
38
39 =head1 DESCRIPTION
40
41 =head1 ATTRIBUTES
42
43 =head2 accept_context_sub
44
45 =head1 AUTHORS
46
47 Catalyst Contributors, see Catalyst.pm
48
49 =head1 COPYRIGHT
50
51 This library is free software. You can redistribute it and/or modify it under
52 the same terms as Perl itself.
53
54 =cut