[Catalyst-commits] r7766 - in Catalyst-Runtime/5.80/branches/moose:
lib lib/Catalyst t
groditi at dev.catalyst.perl.org
groditi at dev.catalyst.perl.org
Tue May 20 21:10:52 BST 2008
Author: groditi
Date: 2008-05-20 21:10:51 +0100 (Tue, 20 May 2008)
New Revision: 7766
Modified:
Catalyst-Runtime/5.80/branches/moose/lib/Catalyst.pm
Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Controller.pm
Catalyst-Runtime/5.80/branches/moose/t/unit_controller_namespace.t
Catalyst-Runtime/5.80/branches/moose/t/unit_core_action_for.t
Log:
making $app be an instance, less symbol table hijacking, cache path_prefix and action_namespace
Modified: Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Controller.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Controller.pm 2008-05-20 08:11:55 UTC (rev 7765)
+++ Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Controller.pm 2008-05-20 20:10:51 UTC (rev 7766)
@@ -12,7 +12,7 @@
has path_prefix =>
(
- is => 'ro',
+ is => 'rw',
isa => 'Str',
init_arg => 'path',
predicate => 'has_path_prefix',
@@ -20,7 +20,7 @@
has action_namespace =>
(
- is => 'ro',
+ is => 'rw',
isa => 'Str',
init_arg => 'namespace',
predicate => 'has_action_namespace',
@@ -149,7 +149,8 @@
if( ref($self) ){
return $self->$orig if $self->has_action_namespace;
} else {
- # if the following won't change at runtime it should be lazy_building thing
+ warn "action_namespace called as class method";
+ # if the following won't change at runtime it should be lazy_building thing
return $self->config->{namespace} if exists $self->config->{namespace};
}
@@ -171,7 +172,9 @@
}
}
- return Catalyst::Utils::class2prefix(ref($self) || $self, $case_s) || '';
+ my $namespace = Catalyst::Utils::class2prefix(ref($self) || $self, $case_s) || '';
+ $self->$orig($namespace) if ref($self);
+ return $namespace;
};
#Once again, this is probably better written as a builder method
@@ -183,7 +186,9 @@
} else {
return $self->config->{path} if exists $self->config->{path};
}
- return $self->action_namespace(@_);
+ my $namespace = $self->action_namespace(@_);
+ $self->$orig($namespace) if ref($self);
+ return $namespace;
};
@@ -192,26 +197,18 @@
my $class = ref $self || $self;
#this is still not correct for some reason.
my $namespace = $self->action_namespace($c);
- my %methods;
- if( $self->can('meta') ){
- my $meta = $self->meta;
- %methods = map{ $_->{code}->body => $_->{name} }
+ my $meta = $self->meta;
+ my %methods = map{ $_->{code}->body => $_->{name} }
grep {$_->{class} ne 'Moose::Object'} #ignore Moose::Object methods
- $meta->compute_all_applicable_methods;
- } else { #until we are sure there's no moose stuff left...
- $methods{ $self->can($_) } = $_
- for @{ Class::Inspector->methods($class) || [] };
- }
+ $meta->compute_all_applicable_methods;
+
# Advanced inheritance support for plugins and the like
- #to be modified to use meta->superclasses
#moose todo: migrate to eliminate CDI compat
my @action_cache;
- {
- no strict 'refs';
- for my $isa ( @{"$class\::ISA"}, $class ) {
- push @action_cache, @{ $isa->_action_cache }
- if $isa->can('_action_cache');
+ for my $isa ( $meta->superclasses, $class ) {
+ if(my $coderef = $isa->can('_action_cache')){
+ push(@action_cache, @{ $isa->$coderef });
}
}
Modified: Catalyst-Runtime/5.80/branches/moose/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/moose/lib/Catalyst.pm 2008-05-20 08:11:55 UTC (rev 7765)
+++ Catalyst-Runtime/5.80/branches/moose/lib/Catalyst.pm 2008-05-20 20:10:51 UTC (rev 7766)
@@ -89,22 +89,18 @@
# callers @ISA.
return unless $class eq 'Catalyst';
- my $caller = caller(0);
+ my $caller = caller();
+ return if $caller eq 'main';
+ my $meta = Moose::Meta::Class->initialize($caller);
+ #Moose->import({ into => $caller }); #do we want to do this?
- #why does called have to ISA Catalyst and ISA Controller ?
- #Convert test suite to not use the behavior where Myapp ISA Controller
- # after that is done we can eliminate that little mess.
unless ( $caller->isa('Catalyst') ) {
- no strict 'refs';
- if( $caller->can('meta') ){
- my @superclasses = ($caller->meta->superclasses, $class, 'Catalyst::Controller');
- #my @superclasses = ($caller->meta->superclasses, $class);
- $caller->meta->superclasses(@superclasses);
- } else {
- push @{"$caller\::ISA"}, $class, 'Catalyst::Controller';
- #push @{"$caller\::ISA"}, $class;
- }
+ my @superclasses = ($meta->superclasses, $class, 'Catalyst::Controller');
+ $meta->superclasses(@superclasses);
}
+ unless( $meta->has_method('meta') ){
+ $meta->add_method(meta => sub { Moose::Meta::Class->initialize("${caller}") } );
+ }
$caller->arguments( [@arguments] );
$caller->setup_home;
@@ -926,7 +922,7 @@
}
# Add our self to components, since we are also a component
- $class->components->{$class} = $class;
+ $class->components->{$class} = $class->setup_component($class);
$class->setup_actions;
@@ -1936,7 +1932,7 @@
Catalyst::Exception->throw(
message =>
qq/Couldn't instantiate component "$component", "COMPONENT() didn't return an object-like value"/
- ) unless eval { $instance->can( 'can' ) };
+ ) unless blessed($instance);
return $instance;
}
@@ -1988,10 +1984,7 @@
if ( $ENV{MOD_PERL} ) {
# create the apache method
- {
- no strict 'refs';
- *{"$class\::apache"} = sub { shift->engine->apache };
- }
+ $class->meta->add_method('apache' => sub { shift->engine->apache });
my ( $software, $version ) =
$ENV{MOD_PERL} =~ /^(\S+)\/(\d+(?:[\.\_]\d+)+)/;
@@ -2126,9 +2119,7 @@
my $env_debug = Catalyst::Utils::env_value( $class, 'DEBUG' );
if ( defined($env_debug) ? $env_debug : $debug ) {
- no strict 'refs';
- #Moose todo: dying to be made a bool attribute
- *{"$class\::debug"} = sub { 1 };
+ $class->meta->add_method('debug' => sub { 1 });
$class->log->debug('Debug messages enabled');
}
}
@@ -2152,9 +2143,7 @@
my $env = Catalyst::Utils::env_value( $class, 'STATS' );
if ( defined($env) ? $env : ($stats || $class->debug ) ) {
- no strict 'refs';
- #Moose todo: dying to be made a bool attribute
- *{"$class\::use_stats"} = sub { 1 };
+ $class->meta->add_method('use_stats' => sub { 1 });
$class->log->debug('Statistics enabled');
}
}
Modified: Catalyst-Runtime/5.80/branches/moose/t/unit_controller_namespace.t
===================================================================
--- Catalyst-Runtime/5.80/branches/moose/t/unit_controller_namespace.t 2008-05-20 08:11:55 UTC (rev 7765)
+++ Catalyst-Runtime/5.80/branches/moose/t/unit_controller_namespace.t 2008-05-20 20:10:51 UTC (rev 7766)
@@ -19,6 +19,6 @@
sub config { {} };
}
-is(MyApp::Controller::Foo->action_namespace('Stub'), 'foo');
+is(MyApp::Controller::Foo->COMPONENT->action_namespace('Stub'), 'foo');
-is(MyApp::Controller::Root->action_namespace('Stub'), '');
+is(MyApp::Controller::Root->COMPONENT->action_namespace('Stub'), '');
Modified: Catalyst-Runtime/5.80/branches/moose/t/unit_core_action_for.t
===================================================================
--- Catalyst-Runtime/5.80/branches/moose/t/unit_core_action_for.t 2008-05-20 08:11:55 UTC (rev 7765)
+++ Catalyst-Runtime/5.80/branches/moose/t/unit_core_action_for.t 2008-05-20 20:10:51 UTC (rev 7766)
@@ -12,7 +12,7 @@
use_ok('TestApp');
-is(TestApp->action_for('global_action')->code, TestApp->can('global_action'),
+is(TestApp->component('TestApp')->action_for('global_action')->code, TestApp->can('global_action'),
'action_for on appclass ok');
is(TestApp->controller('Args')->action_for('args')->code,
More information about the Catalyst-commits
mailing list