File Coverage

blib/lib/Catalyst/Component/ApplicationAttribute.pm
Criterion Covered Total %
statement 6 7 85.7
branch n/a
condition n/a
subroutine 2 3 66.6
pod n/a
total 8 10 80.0


line stmt bran cond sub pod time code
1             package Catalyst::Component::ApplicationAttribute;
2              
3 167     167   115694 use Moose::Role;
  167         572  
  167         1499  
4 167     167   928748 use namespace::clean -except => 'meta';
  167         587  
  167         1752  
5              
6             # Future - isa => 'ClassName|Catalyst' performance?
7             # required => 1 breaks tests..
8             has _application => (is => 'ro', weak_ref => 1);
9 0     0     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;
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';
34              
35             # Your code here
36              
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              
70             This library is free software. You can redistribute it and/or modify it under
71             the same terms as Perl itself.
72              
73             =cut