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
=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 {
. " did not override Catalyst::Component::process" );
}
+
+__PACKAGE__->meta->make_immutable;
1;
__END__