X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FComponent.pm;h=feab1cf8a59684c2c71168c6e01620716cb5f6b6;hp=5718b28fa987e5e9e1f51c05536ce44ea50c83aa;hb=22247e54ccd3fbdaf286e77304b96e61ecc43a0f;hpb=684d10edf63074f94667d437db01d30b8d13cefc diff --git a/lib/Catalyst/Component.pm b/lib/Catalyst/Component.pm index 5718b28..feab1cf 100644 --- a/lib/Catalyst/Component.pm +++ b/lib/Catalyst/Component.pm @@ -15,7 +15,7 @@ Catalyst::Component - Catalyst Component Base Class # lib/MyApp/Model/Something.pm package MyApp::Model::Something; - use base 'Catalyst::Base'; + use base 'Catalyst::Component'; __PACKAGE__->config( foo => 'bar' ); @@ -49,9 +49,7 @@ component loader with config() support and a process() method placeholder. =head1 METHODS -=over 4 - -=item new($c) +=head2 new($c) =cut @@ -64,14 +62,39 @@ sub new { return $self->NEXT::new( { %{ $self->config }, %{$arguments} } ); } -# remember to leave blank lines between the consecutive =item's -# otherwise the pod tools don't recognize the subsequent =items +=head2 COMPONENT($c) + +=cut + +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->config }, %{$arguments} }; + return bless $new, $class; + } + } +} + +# remember to leave blank lines between the consecutive =head2's +# otherwise the pod tools don't recognize the subsequent =head2s -=item $c->config +=head2 $c->config -=item $c->config($hashref) +=head2 $c->config($hashref) -=item $c->config($key, $value, ...) +=head2 $c->config($key, $value, ...) =cut @@ -87,7 +110,7 @@ sub config { return $self->_config; } -=item $c->process() +=head2 $c->process() =cut @@ -97,11 +120,9 @@ sub process { . " did not override Catalyst::Component::process" ); } -=back - =head1 SEE ALSO -L. +L, L, L, L. =head1 AUTHOR