[Catalyst-commits] r11774 - in
Catalyst-Runtime/5.80/branches/basic-app-ctx-separation: lib
lib/Catalyst t t/aggregate
zby at dev.catalyst.perl.org
zby at dev.catalyst.perl.org
Fri Nov 6 14:08:35 GMT 2009
Author: zby
Date: 2009-11-06 14:08:35 +0000 (Fri, 06 Nov 2009)
New Revision: 11774
Added:
Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/lib/Catalyst/Context.pm
Modified:
Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/lib/Catalyst.pm
Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/lib/Catalyst/Dispatcher.pm
Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/aggregate/unit_core_uri_for_action.t
Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/aggregate/unit_core_uri_for_multibytechar.t
Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/unit_core_mvc.t
Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/unit_core_uri_for.t
Log:
request related attributes into a Catalyst::Context object instead of storing it directly in the app
Added: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/lib/Catalyst/Context.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/lib/Catalyst/Context.pm (rev 0)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/lib/Catalyst/Context.pm 2009-11-06 14:08:35 UTC (rev 11774)
@@ -0,0 +1,80 @@
+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
+
Modified: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/lib/Catalyst/Dispatcher.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/lib/Catalyst/Dispatcher.pm 2009-11-05 17:04:43 UTC (rev 11773)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/lib/Catalyst/Dispatcher.pm 2009-11-06 14:08:35 UTC (rev 11774)
@@ -205,11 +205,10 @@
$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);
}
Modified: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/lib/Catalyst.pm 2009-11-05 17:04:43 UTC (rev 11773)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/lib/Catalyst.pm 2009-11-06 14:08:35 UTC (rev 11774)
@@ -6,6 +6,7 @@
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;
@@ -34,15 +35,13 @@
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(@_) }
@@ -1886,7 +1885,8 @@
# 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);
Modified: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/aggregate/unit_core_uri_for_action.t
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/aggregate/unit_core_uri_for_action.t 2009-11-05 17:04:43 UTC (rev 11773)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/aggregate/unit_core_uri_for_action.t 2009-11-06 14:08:35 UTC (rev 11774)
@@ -93,8 +93,10 @@
} );
my $context = TestApp->new( {
- request => $request,
- namespace => 'yada',
+ context => Catalyst::Context->new(
+ request => $request,
+ namespace => 'yada',
+ ),
} );
is($context->uri_for($context->controller('Action')),
Modified: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/aggregate/unit_core_uri_for_multibytechar.t
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/aggregate/unit_core_uri_for_multibytechar.t 2009-11-05 17:04:43 UTC (rev 11773)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/aggregate/unit_core_uri_for_multibytechar.t 2009-11-06 14:08:35 UTC (rev 11774)
@@ -15,8 +15,8 @@
uri => URI->new("$base/"),
});
-my $context = TestApp->new({
- request => $request,
+my $context = TestApp->new({
+ context => Catalyst::Context->new( request => $request, )
});
Modified: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/unit_core_mvc.t
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/unit_core_mvc.t 2009-11-05 17:04:43 UTC (rev 11773)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/unit_core_mvc.t 2009-11-06 14:08:35 UTC (rev 11774)
@@ -69,12 +69,12 @@
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');
{
@@ -91,20 +91,20 @@
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
Modified: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/unit_core_uri_for.t
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/unit_core_uri_for.t 2009-11-05 17:04:43 UTC (rev 11773)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation/t/unit_core_uri_for.t 2009-11-06 14:08:35 UTC (rev 11774)
@@ -11,8 +11,7 @@
} );
my $context = Catalyst->new( {
- request => $request,
- namespace => 'yada',
+ context => Catalyst::Context->new( request => $request, namespace => 'yada' ),
} );
is(
More information about the Catalyst-commits
mailing list