use Moose::Util qw/find_meta/;
use bytes;
use B::Hooks::EndOfScope ();
+use Catalyst::Context;
use Catalyst::Exception;
use Catalyst::Exception::Detach;
use Catalyst::Exception::Go;
BEGIN { require 5.008004; }
-has stack => (is => 'ro', default => sub { [] });
-has stash => (is => 'rw', default => sub { {} });
-has state => (is => 'rw', default => 0);
-has stats => (is => 'rw');
-has action => (is => 'rw');
-has counter => (is => 'rw', default => sub { {} });
-has request => (is => 'rw', default => sub { $_[0]->request_class->new({}) }, required => 1, lazy => 1);
-has response => (is => 'rw', default => sub { $_[0]->response_class->new({}) }, required => 1, lazy => 1);
-has namespace => (is => 'rw');
+has 'context' => (
+ isa => 'Catalyst::Context',
+ is => 'rw',
+ handles => [
+ qw/ action counter namespace request response stack stash state stats /,
+ ],
+);
sub depth { scalar @{ shift->stack || [] }; }
sub comp { shift->component(@_) }
# into the application.
$class->context_class( ref $class || $class ) unless $class->context_class;
- my $c = $class->context_class->new({});
+ my $context = Catalyst::Context->new();
+ my $c = $class->context_class->new({ context => $context });
# For on-demand data
$c->request->_context($c);
--- /dev/null
+package Catalyst::Context;
+
+use Moose;
+
+BEGIN { require 5.008004; }
+
+has action => (is => 'rw');
+has counter => (is => 'rw', default => sub { {} });
+has namespace => (is => 'rw');
+has request_class => (is => 'ro', default => 'Catalyst::Request');
+has request => (is => 'rw', default => sub { $_[0]->request_class->new({}) }, required => 1, lazy => 1);
+has response_class => (is => 'ro', default => 'Catalyst::Response');
+has response => (is => 'rw', default => sub { $_[0]->response_class->new({}) }, required => 1, lazy => 1);
+has stack => (is => 'ro', default => sub { [] });
+has stash => (is => 'rw', default => sub { {} });
+has state => (is => 'rw', default => 0);
+has stats => (is => 'rw');
+
+# Remember to update this in Catalyst::Runtime as well!
+
+our $VERSION = '5.80013';
+
+{
+ my $dev_version = $VERSION =~ /_\d{2}$/;
+ *_IS_DEVELOPMENT_VERSION = sub () { $dev_version };
+}
+
+$VERSION = eval $VERSION;
+
+no Moose;
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
+__END__
+
+=head1 NAME
+
+Catalyst::Context - object for keeping request related state
+
+=head1 ATTRIBUTES
+
+=head3 action
+
+=head3 counter
+
+=head3 namespace
+
+=head3 request_class
+
+=head3 request
+
+=head3 response_class
+
+=head3 response
+
+=head3 stack
+
+=head3 stash
+
+=head3 state
+
+=head3 stats
+
+=head1 SEE ALSO
+
+L<Catalyst>, L<Catalyst::Model>, L<Catalyst::View>, 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
+
$action = $self->expand_action($action);
- local $c->request->{arguments} = $args;
- local $c->request->{captures} = $captures;
- local $c->{namespace} = $action->{'namespace'};
- local $c->{action} = $action;
-
+ local $c->context->request->{arguments} = $args;
+ local $c->context->request->{captures} = $captures;
+ local $c->context->{namespace} = $action->{'namespace'};
+ local $c->context->{action} = $action;
$self->dispatch($c);
}
} );
my $context = TestApp->new( {
- request => $request,
- namespace => 'yada',
+ context => Catalyst::Context->new(
+ request => $request,
+ namespace => 'yada',
+ ),
} );
is($context->uri_for($context->controller('Action')),
uri => URI->new("$base/"),
});
-my $context = TestApp->new({
- request => $request,
+my $context = TestApp->new({
+ context => Catalyst::Context->new( request => $request, )
});
ok( $warnings, 'view() w/o a default is random, warnings thrown' );
}
-is ( bless ({stash=>{current_view=>'V'}}, 'MyApp')->view , 'MyApp::View::V', 'current_view ok');
+is ( bless ( { context => Catalyst::Context->new(stash=>{current_view=>'V'}) }, 'MyApp')->view , 'MyApp::View::V', 'current_view ok');
my $view = bless {} , 'MyApp::View::V';
-is ( bless ({stash=>{current_view_instance=> $view }}, 'MyApp')->view , $view, 'current_view_instance ok');
+is ( bless ({ context => Catalyst::Context->new(stash=>{current_view_instance=> $view })}, 'MyApp')->view , $view, 'current_view_instance ok');
-is ( bless ({stash=>{current_view_instance=> $view, current_view=>'MyApp::V::View' }}, 'MyApp')->view , $view,
+is ( bless ({ context => Catalyst::Context->new(stash=>{current_view_instance=> $view, current_view=>'MyApp::V::View' })}, 'MyApp')->view , $view,
'current_view_instance precedes current_view ok');
{
ok( $warnings, 'model() w/o a default is random, warnings thrown' );
}
-is ( bless ({stash=>{current_model=>'M'}}, 'MyApp')->model , 'MyApp::Model::M', 'current_model ok');
+is ( bless({ context => Catalyst::Context->new({stash=>{current_model=>'M'}})}, 'MyApp')->model , 'MyApp::Model::M', 'current_model ok');
my $model = bless {} , 'MyApp::Model::M';
-is ( bless ({stash=>{current_model_instance=> $model }}, 'MyApp')->model , $model, 'current_model_instance ok');
+is ( bless ({context => Catalyst::Context->new(stash=>{current_model_instance=> $model })}, 'MyApp')->model , $model, 'current_model_instance ok');
-is ( bless ({stash=>{current_model_instance=> $model, current_model=>'MyApp::M::Model' }}, 'MyApp')->model , $model,
+is ( bless ({context => Catalyst::Context->new(stash=>{current_model_instance=> $model, current_model=>'MyApp::M::Model' })}, 'MyApp')->model , $model,
'current_model_instance precedes current_model ok');
MyApp->config->{default_view} = 'V';
-is ( bless ({stash=>{}}, 'MyApp')->view , 'MyApp::View::V', 'default_view ok');
+is ( bless ({context => Catalyst::Context->new(stash=>{})}, 'MyApp')->view , 'MyApp::View::V', 'default_view ok');
is ( MyApp->view , 'MyApp::View::V', 'default_view in class method ok');
MyApp->config->{default_model} = 'M';
-is ( bless ({stash=>{}}, 'MyApp')->model , 'MyApp::Model::M', 'default_model ok');
+is ( bless ({context => Catalyst::Context->new(stash=>{})}, 'MyApp')->model , 'MyApp::Model::M', 'default_model ok');
is ( MyApp->model , 'MyApp::Model::M', 'default_model in class method ok');
# regexp behavior tests
} );
my $context = Catalyst->new( {
- request => $request,
- namespace => 'yada',
+ context => Catalyst::Context->new( request => $request, namespace => 'yada' ),
} );
is(