Commit | Line | Data |
---|---|---|
a6c13ff4 | 1 | package Catalyst::IOC::Service::WithAcceptContext; |
5fabf3ec | 2 | use Moose::Role; |
3 | ||
5fabf3ec | 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 { | |
17fe1041 | 13 | my $orig = shift; |
14 | my $self = shift; | |
5fabf3ec | 15 | |
17fe1041 | 16 | my $instance = $self->$orig(@_); |
38215fbf | 17 | |
17fe1041 | 18 | my $accept_context_args = $self->param('accept_context_args'); |
19 | my $ac_sub = $self->accept_context_sub; | |
5fabf3ec | 20 | |
a42c4b8a | 21 | if ( $accept_context_args && $instance->can($ac_sub) ) { |
4f38bf4b | 22 | return $instance->$ac_sub( @$accept_context_args ); |
5fabf3ec | 23 | } |
24 | ||
25 | return $instance; | |
26 | }; | |
27 | ||
28 | no Moose::Role; | |
29 | 1; | |
bf3c8088 | 30 | |
31 | __END__ | |
32 | ||
33 | =pod | |
34 | ||
35 | =head1 NAME | |
36 | ||
17fe1041 | 37 | Catalyst::Service::WithAcceptContext |
bf3c8088 | 38 | |
39 | =head1 DESCRIPTION | |
40 | ||
1ab07ed4 | 41 | =head1 ATTRIBUTES |
bf3c8088 | 42 | |
1ab07ed4 | 43 | =head2 accept_context_sub |
bf3c8088 | 44 | |
e8ed391e | 45 | =head1 AUTHORS |
bf3c8088 | 46 | |
e8ed391e | 47 | Catalyst Contributors, see Catalyst.pm |
bf3c8088 | 48 | |
e8ed391e | 49 | =head1 COPYRIGHT |
bf3c8088 | 50 | |
e8ed391e | 51 | This library is free software. You can redistribute it and/or modify it under |
52 | the same terms as Perl itself. | |
bf3c8088 | 53 | |
54 | =cut |