Commit | Line | Data |
c1ec627e |
1 | package Catalyst::Component::ApplicationAttribute; |
9cc543bc |
2 | |
3 | use Moose::Role; |
4 | use namespace::clean -except => 'meta'; |
5 | |
6 | # Future - isa => 'ClassName|Catalyst' performance? |
7 | # required => 1 breaks tests.. |
8d4ef431 |
8 | has _application => (is => 'ro', weak_ref => 1); |
9cc543bc |
9 | sub _app { (shift)->_application(@_) } |
10 | |
11 | override BUILDARGS => sub { |
12 | my ($self, $app) = @_; |
13 | |
14 | my $args = super(); |
15 | $args->{_application} = $app; |
16 | |
17 | return $args; |
18 | }; |
19 | |
20 | 1; |
1a23d3da |
21 | |
22 | __END__ |
23 | |
24 | =head1 NAME |
25 | |
26 | Catalyst::Component::ApplicationAttribute - Moose Role for components which capture the application context. |
27 | |
28 | =head1 SYNOPSIS |
29 | |
30 | package My::Component; |
31 | use Moose; |
32 | extends 'Catalyst::Component'; |
33 | with 'Catalyst::Component::ApplicationAttribute'; |
b0ad47c1 |
34 | |
1a23d3da |
35 | # Your code here |
b0ad47c1 |
36 | |
1a23d3da |
37 | 1; |
38 | |
39 | =head1 DESCRIPTION |
40 | |
41 | This role provides a BUILDARGS method which captures the application context into an attribute. |
42 | |
43 | =head1 ATTRIBUTES |
44 | |
45 | =head2 _application |
46 | |
47 | Weak reference to the application context. |
48 | |
49 | =head1 METHODS |
50 | |
51 | =head2 BUILDARGS ($self, $app) |
52 | |
53 | BUILDARGS method captures the application context into the C<_application> attribute. |
54 | |
55 | =head2 _application |
56 | |
57 | Reader method for the application context. |
58 | |
59 | =head1 SEE ALSO |
60 | |
61 | L<Catalyst::Component>, |
62 | L<Catalyst::Controller>. |
63 | |
64 | =head1 AUTHORS |
65 | |
66 | Catalyst Contributors, see Catalyst.pm |
67 | |
68 | =head1 COPYRIGHT |
69 | |
536bee89 |
70 | This library is free software. You can redistribute it and/or modify it under |
1a23d3da |
71 | the same terms as Perl itself. |
72 | |
73 | =cut |