Stop calling class data methods on instances + commented out warning
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Component.pm
index c065664..fe0ef6f 100644 (file)
@@ -60,7 +60,17 @@ component loader with config() support and a process() method placeholder.
 __PACKAGE__->mk_classdata('_plugins');
 __PACKAGE__->mk_classdata('_config');
 
-has _component_name => ( is => 'ro' );
+has catalyst_component_name => ( is => 'ro' ); # Cannot be required => 1 as context
+                                       # class @ISA component - HATE
+# Make accessor callable as a class method, as we need to call setup_actions
+# on the application class, which we don't have an instance of, ewwwww
+# Also, naughty modules like Catalyst::View::JSON try to write to _everything_,
+# so spit a warning, ignore that (and try to do the right thing anyway) here..
+around catalyst_component_name => sub {
+    my ($orig, $self) = (shift, shift);
+    Carp::cluck("Tried to write to the catalyst_component_name accessor - is your component broken or just mad? (Write ignored - using default value.)") if scalar @_;
+    blessed($self) ? $self->$orig() || blessed($self) : $self;
+};
 
 sub BUILDARGS {
     my $class = shift;
@@ -103,6 +113,8 @@ sub COMPONENT {
 
 sub config {
     my $self = shift;
+    # Uncomment once sane to do so
+    #Carp::cluck("config method called on instance") if ref $self;
     my $config = $self->_config || {};
     if (@_) {
         my $newconfig = { %{@_ > 1 ? {@_} : $_[0]} };
@@ -172,15 +184,6 @@ something like this:
       return $class->new($app, $args);
   }
 
-=head2 _component_name
-
-The name of the component within an application. This is used to
-pass the component's name to actions generated (becoming
-C<< $action->class >>). This is needed so that the L</COMPONENT> method can
-return an instance of a different class (e.g. a L<Class::MOP> anonymous class),
-(as finding the component name by C<< ref($self) >> will not work correctly in
-such cases).
-
 =head2 $c->config
 
 =head2 $c->config($hashref)