File Coverage

blib/lib/Catalyst/Model/InjectionHelpers/PerRequest.pm
Criterion Covered Total %
statement 10 10 100.0
branch 2 4 50.0
condition 2 3 66.6
subroutine 3 3 100.0
pod 0 1 0.0
total 17 21 80.9


line stmt bran cond sub pod time code
1             package Catalyst::Model::InjectionHelpers::PerRequest;
2              
3 2     2   15 use Moose;
  2         4  
  2         18  
4 2     2   12215 use Scalar::Util qw/blessed refaddr/;
  2         4  
  2         385  
5              
6             with 'Catalyst::ComponentRole::InjectionHelpers';
7              
8             sub ACCEPT_CONTEXT {
9 6     6 0 178415 my ($self, $c, @args) = @_;
10 6 50       23 return $self->build_new_instance($c, @args) unless blessed $c;
11 6 50       24 my $key = blessed $self ? refaddr $self : $self;
12 6   66     17 return $c->stash->{"__InstancePerContext_${key}"} ||=
13             $self->build_new_instance($c, @args);
14             }
15              
16             __PACKAGE__->meta->make_immutable;
17              
18             =head1 NAME
19              
20             Catalyst::Model::InjectionHelpers::PerRequest - Adaptor that returns a request scoped model
21              
22             =head1 SYNOPSIS
23              
24             package MyApp;
25              
26             use Catalyst 'InjectionHelper';
27              
28             MyApp->inject_components(
29             'Model::PerRequest' => {
30             from_class=>'MyApp::PerRequest',
31             adaptor=>'PerRequest',
32             method=>'new'
33             });
34              
35             MyApp->config(
36             'Model::Factory' => { aaa=>100 },
37             );
38              
39             MyApp->setup;
40            
41             =head1 DESCRIPTION
42              
43             Injection helper adaptor that returns a new model once for each request, scoped
44             to the request. See L<Catalyst::Plugin::InjectionHelpers> for details.
45              
46             =head1 AUTHOR
47              
48             John Napiorkowski L<email:jjnapiork@cpan.org>
49            
50             =head1 SEE ALSO
51            
52             L<Catalyst::Plugin::InjectionHelpers>
53             L<Catalyst>, L<Catalyst::Model::InjectionHelpers::Application>,
54             L<Catalyst::Model::InjectionHelpers::Factory>, L<Catalyst::Model::InjectionHelpers::PerRequest>
55             L<Catalyst::ModelRole::InjectionHelpers>
56              
57             =head1 COPYRIGHT & LICENSE
58            
59             Copyright 2016, John Napiorkowski L<email:jjnapiork@cpan.org>
60            
61             This library is free software; you can redistribute it and/or modify it under
62             the same terms as Perl itself.
63            
64             =cut