X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FComponent.pm;h=36b05236f47514b294e258be5d7352d6df328b5d;hb=74c89dead3cfd8e95cbe853adbc6fe9eed539f4e;hp=62ab0666263180cb95e3512b833efd5b5577993f;hpb=85d9fce671016c9040775c8b4458cf9c72ec2208;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Component.pm b/lib/Catalyst/Component.pm index 62ab066..36b0523 100644 --- a/lib/Catalyst/Component.pm +++ b/lib/Catalyst/Component.pm @@ -1,9 +1,16 @@ package Catalyst::Component; -use strict; -use base qw/Class::Accessor::Fast Class::Data::Inheritable/; -use NEXT; +use Moose; +use Class::MOP; +use Class::MOP::Object; +use MooseX::Adopt::Class::Accessor::Fast; use Catalyst::Utils; +use Class::C3::Adopt::NEXT; +use MRO::Compat; +use mro 'c3'; + +with 'MooseX::Emulate::Class::Accessor::Fast'; +with 'Catalyst::ClassData'; =head1 NAME @@ -49,18 +56,18 @@ component loader with config() support and a process() method placeholder. =cut -__PACKAGE__->mk_classdata($_) for qw/_config _plugins/; - - - -sub new { - my ( $self, $c ) = @_; +__PACKAGE__->mk_classdata('_plugins'); +__PACKAGE__->mk_classdata('_config'); +sub BUILDARGS { + my ($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 ); + + return $args; } sub COMPONENT { @@ -68,34 +75,35 @@ sub COMPONENT { # 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 = {} ); - } + my $config = $self->_config || {}; if (@_) { my $newconfig = { %{@_ > 1 ? {@_} : $_[0]} }; $self->_config( $self->merge_config_hashes( $config, $newconfig ) ); + } else { + # this is a bit of a kludge, required to make + # __PACKAGE__->config->{foo} = 'bar'; + # work in a subclass. If we don't have the package symbol in the + # current class we know we need to copy up to ours, which calling + # the setter will do for us. + my $meta = $self->Class::MOP::Object::meta(); + unless ($meta->has_package_symbol('$_config')) { + + $config = $self->merge_config_hashes( $config, {} ); + $self->_config( $config ); + } } return $config; } @@ -112,6 +120,9 @@ sub process { . " did not override Catalyst::Component::process" ); } +no Moose; + +__PACKAGE__->meta->make_immutable; 1; __END__ @@ -173,11 +184,9 @@ calling code in the application rather than the component itself. L, L, L, L. -=head1 AUTHOR +=head1 AUTHORS -Sebastian Riedel, C -Marcus Ramberg, C -Matt S Trout, C +Catalyst Contributors, see Catalyst.pm =head1 COPYRIGHT