X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FComponent%2FApplicationAttribute.pm;fp=lib%2FCatalyst%2FComponent%2FApplicationAttribute.pm;h=bf86bedbda300e86a101cd9fe2588c3a617ce108;hb=4a41d5d1ec3187cc41e15767b21c14b2aee31740;hp=0000000000000000000000000000000000000000;hpb=2757db2c7c600c8a0b8e2b4366f38c97804c2844;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Component/ApplicationAttribute.pm b/lib/Catalyst/Component/ApplicationAttribute.pm new file mode 100644 index 0000000..bf86bed --- /dev/null +++ b/lib/Catalyst/Component/ApplicationAttribute.pm @@ -0,0 +1,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, +L. + +=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