1 package Catalyst::Component::ACCEPT_CONTEXT;
6 use Scalar::Util qw(weaken);
10 Catalyst::Component::ACCEPT_CONTEXT - Make the current Catalyst
11 request context available in Models and Views.
19 our $VERSION = '0.05';
23 Models and Views don't usually have access to the request object,
24 since they probably don't really need it. Sometimes, however, having
25 the request context available outside of Controllers makes your
26 application cleaner. If that's the case, just use this module as a
29 package MyApp::Model::Foobar;
30 use base qw|Catalyst::Component::ACCEPT_CONTEXT Catalyst::Model|;
32 Then, you'll be able to get the current request object from within
37 print "The current URL is ". $self->context->req->uri->as_string;
44 Returns the current request context.
49 return shift->{context};
54 Catalyst calls this method to give the current context to your model.
55 You should never call it directly.
57 Note that a new instance of your component isn't created. All we do
58 here is shove C<$c> into your component. ACCEPT_CONTEXT allows for
59 other behavior that may be more useful; if you want something else to
60 happen just implement it yourself.
62 See L<Catalyst::Component> for details.
70 $self->{context} = $context;
71 weaken($self->{context});
73 return $self->NEXT::ACCEPT_CONTEXT($context, @_) || $self;
78 Overridden to use initial application object as context before a request.
86 $args->{context} = $app;
87 weaken($args->{context}) if ref $args->{context};
88 return $class->NEXT::COMPONENT($app, $args, @_);
93 Jonathan Rockway, C<< <jrockway at cpan.org> >>
97 Please report any bugs or feature requests to
98 C<bug-catalyst-component-accept_context at rt.cpan.org>, or through the web interface at
99 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Component-ACCEPT_CONTEXT>.
100 I will be notified, and then you'll automatically be notified of progress on
101 your bug as I make changes.
105 You can find documentation for this module with the perldoc command.
107 perldoc Catalyst::Component::ACCEPT_CONTEXT
109 You can also look for information at:
113 =item * Catalyst Website
115 L<http://www.catalystframework.org/>
117 =item * AnnoCPAN: Annotated CPAN documentation
119 L<http://annocpan.org/dist/Catalyst-Component-ACCEPT_CONTEXT>
123 L<http://cpanratings.perl.org/d/Catalyst-Component-ACCEPT_CONTEXT>
125 =item * RT: CPAN's request tracker
127 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Component-ACCEPT_CONTEXT>
131 L<http://search.cpan.org/dist/Catalyst-Component-ACCEPT_CONTEXT>
135 =head1 COPYRIGHT & LICENSE
137 Copyright 2007 Jonathan Rockway.
139 This program is free software; you can redistribute it and/or modify it
140 under the same terms as Perl itself.
144 1; # End of Catalyst::Component::ACCEPT_CONTEXT