X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FComponent.pm;h=2950f4458af9b3a0b1ec7c9ebd7c0cf9501c5c9a;hb=46d0346ddafe8e167c679cddef9834946598e689;hp=9926298d2fef92d0c59a8f41a9d4c927786a4b32;hpb=7cd1a42bb51b6004005cbadc304b3bb5849e2a4f;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Component.pm b/lib/Catalyst/Component.pm index 9926298..2950f44 100644 --- a/lib/Catalyst/Component.pm +++ b/lib/Catalyst/Component.pm @@ -1,9 +1,14 @@ package Catalyst::Component; -use strict; -use base qw/Class::Accessor::Fast Class::Data::Inheritable/; -use NEXT; +use Moose; +use Class::MOP; +use MooseX::Adopt::Class::Accessor::Fast; use Catalyst::Utils; +use MRO::Compat; +use mro 'c3'; + +with 'MooseX::Emulate::Class::Accessor::Fast'; +with 'Catalyst::ClassData'; =head1 NAME @@ -49,55 +54,68 @@ component loader with config() support and a process() method placeholder. =cut -__PACKAGE__->mk_classdata($_) for qw/_config _plugins/; - +__PACKAGE__->mk_classdata('_plugins'); - -sub new { - my ( $self, $c ) = @_; +around new => sub { + my ( $orig, $self) = @_; # Temporary fix, some components does not pass context to constructor my $arguments = ( ref( $_[-1] ) eq 'HASH' ) ? $_[-1] : {}; - return $self->NEXT::new( - $self->merge_config_hashes( $self->config, $arguments ) ); -} + my $args = $self->merge_config_hashes( $self->config, $arguments ); + $self->$orig( $args ); +}; + +no Moose; sub COMPONENT { my ( $self, $c ) = @_; # Temporary fix, some components does not pass context to constructor my $arguments = ( ref( $_[-1] ) eq 'HASH' ) ? $_[-1] : {}; - - if ( my $new = $self->NEXT::COMPONENT( $c, $arguments ) ) { - return $new; - } - else { - if ( my $new = $self->new( $c, $arguments ) ) { - return $new; - } - else { - my $class = ref $self || $self; - my $new = $self->merge_config_hashes( - $self->config, $arguments ); - return bless $new, $class; - } + if( my $next = $self->next::can ){ + my $class = blessed $self || $self; + my ($next_package) = Class::MOP::get_code_info($next); + warn "There is a COMPONENT method resolving after Catalyst::Component in ${next_package}. This behavior is deprecated and will stop working in future releases."; + return $next->($self, $arguments); } + return $self->new($c, $arguments); } sub config { - my $self = shift; - my $config = $self->_config; - unless ($config) { - $self->_config( $config = {} ); - } - if (@_) { - my $newconfig = { %{@_ > 1 ? {@_} : $_[0]} }; - $self->_config( - $self->merge_config_hashes( $config, $newconfig ) - ); + my $self = shift; + my $class = blessed $self || $self; + + my $config; + my $meta = $class->meta; + if( $meta->has_package_symbol('$config') ){ + $config = ${ $meta->get_package_symbol('$config') }; + } else { + foreach my $super ( $meta->linearized_isa ) { + my $super_meta = Moose::Meta::Class->initialize($super); + if( $super_meta->has_package_symbol('$config') ){ + $config = ${ $super_meta->get_package_symbol('$config') }; + unless( @_ ){ #don't copy and write it twice + $config = $class->merge_config_hashes( $config, {} ); + $meta->add_package_symbol('$config', \ $config); + } + last; + } } - return $config; + } + + unless( defined $config ){ + $config = {}; + $meta->add_package_symbol('$config', \ $config) unless @_; + } + + if (@_) { + my $from_args = { %{@_ > 1 ? {@_} : $_[0]} }; + my $new_config = $class->merge_config_hashes( $config, $from_args); + $meta->add_package_symbol('$config', \ $new_config); + } + + return $config; } sub merge_config_hashes { @@ -112,6 +130,8 @@ sub process { . " did not override Catalyst::Component::process" ); } + +__PACKAGE__->meta->make_immutable; 1; __END__ @@ -184,4 +204,4 @@ Matt S Trout, C This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. -=cut \ No newline at end of file +=cut