File Coverage

blib/lib/Catalyst/Model/Factory/PerRequest.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Catalyst::Model::Factory::PerRequest;
2 1     1   2911 use strict;
  1         3  
  1         36  
3 1     1   5 use warnings;
  1         1  
  1         28  
4 1     1   5 use MRO::Compat;
  1         2  
  1         31  
5              
6 1     1   5 use base 'Catalyst::Model::Factory';
  1         2  
  1         179  
7              
8             our $VERSION = '0.10';
9              
10             sub ACCEPT_CONTEXT {
11             my ($self, $context, @args) = @_;
12             my $id = '__'. ref $self;
13             return $context->stash->{$id} ||= $self->next::method($context, @args);
14             }
15              
16             1;
17             __END__
18              
19             =head1 NAME
20              
21             Catalyst::Model::Factory::PerRequest - use a plain class as a Catalyst model,
22             instantiating it once per Catalyst request
23              
24             =head1 SYNOPSIS
25              
26             This module works just like
27             L<Catalyst::Model::Factory|Catalyst::Model::Factory>, except that a
28             fresh instance of your adapted class is once per Catalyst request, not
29             every time you ask for the object via C<< $c->model >>.
30              
31             =head1 CUSTOMIZING
32              
33             You can customize your subclass just like
34             L<Catalyst::Model::Adaptor|Catalyst::Model::Adaptor>. Instead of
35             C<$app>, though, you'll get C<$c>, the current request context.
36              
37             =head1 METHODS
38              
39             These methods are called by Catalyst, not by you:
40              
41             =head2 COMPONENT
42              
43             Load your class
44              
45             =head2 ACCEPT_CONTEXT
46              
47             Create an instance of your class and return it.
48              
49             =head1 SEE ALSO
50              
51             For all the critical documentation, see L<Catalyst::Model::Adaptor>.