8f4ebfc0a6f3d84a134d554daffd96fa9c3044cd
[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, $self, %params ) = @_;
14
15     my $accept_context_args = delete $params{accept_context_args};
16
17     my $instance = $self->$orig(%params);
18     my $ac_sub   = $self->accept_context_sub;
19
20     if ( $accept_context_args && $instance->can($ac_sub) ) {
21         return $instance->$ac_sub( @$accept_context_args );
22     }
23
24     return $instance;
25 };
26
27 no Moose::Role;
28 1;
29
30 __END__
31
32 =pod
33
34 =head1 NAME
35
36 Catalyst::Service::WithContext
37
38 =head1 DESCRIPTION
39
40 =head1 METHODS
41
42 =over
43
44 =item B<accept_context_sub>
45
46 =item B<get>
47
48 =back
49
50 =head1 AUTHORS
51
52 Catalyst Contributors, see Catalyst.pm
53
54 =head1 COPYRIGHT
55
56 This library is free software. You can redistribute it and/or modify it under
57 the same terms as Perl itself.
58
59 =cut