in reply to Re: Class::Struct - Not a CODE referemce
in thread Class::Struct - Not a CODE referemce

Your example works for me too. Sorry. Apparently I took the error out of my code while reducing it to a simpler test case. My production code still exits with "Not a CODE Reference". I tried debugging it, but I do not understand why it crashes while evaluating the if-expression.
1357==>b if ($self->{TT}->call_category($key) != undef) 1358 { 1359 # Do something, never reached 1360 }
use Data::Dumper; print Dumper $key $VAR1 = 'AN-AM-BA';
print Dumper $self->{TT}->call_category $VAR1 = { 'DU-EX-TA' => 16, '*-CM-*' => 145, # Lots more, but not the value of $key. '*-VY-*' => 132 };
print Dumper $self->{TT}->call_category($key) $VAR1 = undef;
n Not a CODE reference at ...
Do you have any pointer what's wrong here?

Replies are listed 'Best First'.
Re^3: Class::Struct - Not a CODE referemce
by almut (Canon) on Jun 08, 2010 at 14:45 UTC
    # Lots more, but not the value of $key

    Where do you set the hash entry (in case you expect it to be set)?

    Anyhow, as you can tell from the $VAR1 = undef in

    print Dumper $self->{TT}->call_category($key) $VAR1 = undef;

    when you try to fetch non-existent entries, you just get undef (not too surprising, actually).  However, it's not the accessor that causes the "Not a CODE reference" issue, but something later in code you haven't shown (otherwise the error would be thrown before Dumper gets the undef).  In other words, it might not have anything to do with Class::Struct.

      You are right, it happens after the accessor. Thank you - problem solved! The n-command is not intuitive in if/elsif/else constructs - at least not for me. Reading the documentation helped ;-) In case someone struggles with the same error - you probably did this:
      $ref->a->($key);
      but meant this:
      $ref->a($key);
      Cheers, Martin