X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=a628d53cf8200577fd85bc0d9bae0cd6b031b77d;hp=9c5bc8cc840cac66477dc743edccb90832eeec58;hb=05d79b223fd5c1594a492fc05faca548e66478d9;hpb=4ac0b9cb8e9043db8a95f44af685c782bf9426e7 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 9c5bc8c..a628d53 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1,7 +1,8 @@ package Catalyst; use Moose; -extends 'Catalyst::Component'; +extends 'Catalyst::Component', 'Class::Accessor::Fast'; +use Moose::Util qw/find_meta/; use bytes; use Scope::Upper (); use Catalyst::Exception; @@ -43,11 +44,9 @@ sub depth { scalar @{ shift->stack || [] }; } sub comp { shift->component(@_) } sub req { - # carp "the use of req() is deprecated in favour of request()"; my $self = shift; return $self->request(@_); } sub res { - # carp "the use of res() is deprecated in favour of response()"; my $self = shift; return $self->response(@_); } @@ -76,7 +75,7 @@ __PACKAGE__->stats_class('Catalyst::Stats'); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.8000_06'; +our $VERSION = '5.80002'; { my $dev_version = $VERSION =~ /_\d{2}$/; @@ -925,9 +924,9 @@ loads and instantiates the given class. MyApp->plugin( 'prototype', 'HTML::Prototype' ); $c->prototype->define_javascript_functions; - + B This method of adding plugins is deprecated. The ability -to add plugins like this B in a Catalyst 5.9. +to add plugins like this B in a Catalyst 5.81. Please do not use this functionality in new code. =cut @@ -935,9 +934,9 @@ Please do not use this functionality in new code. sub plugin { my ( $class, $name, $plugin, @args ) = @_; - # See block comment in t/unit_core_plugin.t + # See block comment in t/unit_core_plugin.t $class->log->warn(qq/Adding plugin using the ->plugin method is deprecated, and will be removed in Catalyst 5.81/); - + $class->_register_plugin( $plugin, 1 ); eval { $plugin->import }; @@ -1056,10 +1055,11 @@ EOF } # Call plugins setup, this is stupid and evil. + # Also screws C3 badly on 5.10, hack to avoid. { no warnings qw/redefine/; local *setup = sub { }; - $class->setup; + $class->setup unless $Catalyst::__AM_RESTARTING; } # Initialize our data structure @@ -1099,7 +1099,7 @@ EOF # applying modifiers). Scope::Upper::reap(sub { my $meta = Class::MOP::get_metaclass_by_name($class); - $meta->make_immutable unless $meta->is_immutable; + $meta->make_immutable(replace_constructor => 1) unless $meta->is_immutable; }, Scope::Upper::SCOPE(1)); $class->setup_finalize; @@ -1482,6 +1482,7 @@ sub execute { push( @{ $c->stack }, $code ); + no warnings 'recursion'; eval { $c->state( $code->execute( $class, $c, @{ $c->req->args } ) || 0 ) }; $c->_stats_finish_execute( $stats_info ) if $c->use_stats and $stats_info; @@ -2162,6 +2163,14 @@ sub setup_components { =cut +sub _controller_init_base_classes { + my ($class, $component) = @_; + foreach my $class ( reverse @{ mro::get_linear_isa($component) } ) { + Moose->init_meta( for_class => $class ) + unless find_meta($class); + } +} + sub setup_component { my( $class, $component ) = @_; @@ -2169,6 +2178,14 @@ sub setup_component { return $component; } + # FIXME - Ugly, ugly hack to ensure the we force initialize non-moose base classes + # nearest to Catalyst::Controller first, no matter what order stuff happens + # to be loaded. There are TODO tests in Moose for this, see + # f2391d17574eff81d911b97be15ea51080500003 + if ($component->isa('Catalyst::Controller')) { + $class->_controller_init_base_classes($component); + } + my $suffix = Catalyst::Utils::class2classsuffix( $component ); my $config = $class->config->{ $suffix } || {}; @@ -2181,11 +2198,16 @@ sub setup_component { ); } - Catalyst::Exception->throw( - message => - qq/Couldn't instantiate component "$component", "COMPONENT() didn't return an object-like value"/ - ) unless blessed($instance); - + unless (blessed $instance) { + my $metaclass = Moose::Util::find_meta($component); + my $method_meta = $metaclass->find_method_by_name('COMPONENT'); + my $component_method_from = $method_meta->associated_metaclass->name; + my $value = defined($instance) ? $instance : 'undef'; + Catalyst::Exception->throw( + message => + qq/Couldn't instantiate component "$component", COMPONENT() method (from $component_method_from) didn't return an object-like value (value was $value)./ + ); + } return $instance; }