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