File: ApplicationAttribute.pm

package info (click to toggle)
libcatalyst-perl 5.80025-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,104 kB
  • ctags: 1,183
  • sloc: perl: 15,616; makefile: 7
file content (73 lines) | stat: -rw-r--r-- 1,401 bytes parent folder | download | duplicates (8)
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
package Catalyst::Component::ApplicationAttribute;

use Moose::Role;
use namespace::clean -except => 'meta';

# Future - isa => 'ClassName|Catalyst' performance?
#           required => 1 breaks tests..
has _application => (is => 'ro', weak_ref => 1);
sub _app { (shift)->_application(@_) }

override BUILDARGS => sub {
    my ($self, $app) = @_;

    my $args = super();
    $args->{_application} = $app;

    return $args;
};

1;

__END__

=head1 NAME

Catalyst::Component::ApplicationAttribute - Moose Role for components which capture the application context.

=head1 SYNOPSIS

    package My::Component;
    use Moose;
    extends 'Catalyst::Component';
    with 'Catalyst::Component::ApplicationAttribute';

    # Your code here

    1;

=head1 DESCRIPTION

This role provides a BUILDARGS method which captures the application context into an attribute.

=head1 ATTRIBUTES

=head2 _application

Weak reference to the application context.

=head1 METHODS

=head2 BUILDARGS ($self, $app)

BUILDARGS method captures the application context into the C<_application> attribute.

=head2 _application

Reader method for the application context.

=head1 SEE ALSO

L<Catalyst::Component>,
L<Catalyst::Controller>.

=head1 AUTHORS

Catalyst Contributors, see Catalyst.pm

=head1 COPYRIGHT

This library is free software. You can redistribute it and/or modify it under
the same terms as Perl itself.

=cut