# 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] );
}
# 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;
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;
}
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+)+)/;
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');
}
}
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');
}
}
has path_prefix =>
(
- is => 'ro',
+ is => 'rw',
isa => 'Str',
init_arg => 'path',
predicate => 'has_path_prefix',
has action_namespace =>
(
- is => 'ro',
+ is => 'rw',
isa => 'Str',
init_arg => 'namespace',
predicate => 'has_action_namespace',
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};
}
}
}
- 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
} 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;
};
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 });
}
}
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'), '');
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,