This file is indexed.

/usr/share/perl5/Catalyst/Component/InstancePerContext.pm is in libcatalyst-component-instancepercontext-perl 0.001001-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package Catalyst::Component::InstancePerContext;

use Moose::Role;
use Scalar::Util qw/blessed refaddr/;
use strict;
use warnings;

our $VERSION = '0.001001';

requires 'build_per_context_instance';

# Hi, this is why I exist:
# <mst> I'd like to see a Catalyst::Component::InstancePerContext role
# <mst> that requires 'build_per_context_instance'
# <mst> and provides an ACCEPT_CONTEXT that does the appropriate magic
# <mst> ACCEPT_CONTEXT would do the stash persist as well

sub ACCEPT_CONTEXT {
    my $self = shift;
    my ($c) = @_;

    return $self->build_per_context_instance(@_) unless ref $c;
    my $key = blessed $self ? refaddr $self : $self;
    return $c->stash->{"__InstancePerContext_${key}"} ||= $self->build_per_context_instance(@_);
}

1;

=head1 NAME

Catalyst::Component::InstancePerContext -
Return a new instance a component on each request

=head1 SYNOPSYS

    package MyComponent;
    use Moose;
    with 'Catalyst::Component::InstancePerContext';

    sub build_per_context_instance{
        my ($self, $c) = @_;
        # ... do your thing here
        return SomeModule->new(%args);
    }

=head1 REQUIRED METHODS

Your consuming class B<must> implement the following method.

=head2 build_per_context_instance

The value returned by this call is what you will receive when you call
$c->component('YourComponent').

=head1 PROVIDED METHODS

This role will add the following method to your consuming class.

=head2 ACCEPT_CONTEXT

If the context is not blessed, it will simple pass through the value of
C<build_per_context_instance>. If context is blessed it will look in the
C<stash> for an instance of the requested component and return that or,
if the value is not found, the value returned by C<build_per_context_instance>
will be stored and return.

The idea behind this behavior is that a component can be built on a
per-request basis, as the name of this module implies.

=head1 SEE ALSO

L<Moose>, L<Moose::Role>, L<Catalyst::Component>

=head1 AUTHOR

Guillermo Roditi (groditi) <groditi@cpan.org>

=head1 LICENSE

You may distribute this code under the same terms as Perl itself.

=cut