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