Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Desperatly seeking CSW (Class::Std Wisdom)

by krisahoch (Deacon)
on Aug 08, 2006 at 13:10 UTC ( [id://566149]=perlquestion: print w/replies, xml ) Need Help??

krisahoch has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

After spending much time trying to figure out something (which I should not need help figuring out), I am bringing my problem to y'all (not from Texas, just live here).

I am having an issue trying to add a value to a variable. The variable is defined as per the documentation (see below). The main issue here is that I am storing a hash in the variable, and I want to be able to assign keys to the hash via class method (see below).

package My::Class; { use strict; use Class::Std; my %_handler_map :ATTR; # Holds trigger names and states. # ... further down # ================================================================== +========= # METHOD: register_handler(%registration_hash) # REQUIRES: A hash with the following parameters ... # trigger: The state which triggers the handler. # handler: The name space string (Triggered::Handler) which is tr +iggered. # RETURNS: # true: If the trigger and handler both are present and are store +d. # false: If the trigger or handler are not valid (present). # other: An error is thrown if the trigger and handler are valid b +ut # but they do not get stored. # # PURPOSE: Register state handlers and triggers. # ------------------------------------------------------------------ +--------- sub register_state { my ($self, %arguments) = @_; my $trigger = $arguments{'trigger'} || return(undef()); my $handler = $arguments{'handler'} || return(undef()); # ... Here is the part I am having problems with. $_handler_map{ident($self)}{$trigger} = $handler; # Do error checking here. Throw an error if needed. return(1); } } 1;

The error that I am getting is as follows ...
Can't make anonymous subroutine cumulative at <blah>

Is there something that I have overlooked in the Class::Std documentation?

Thank you in advance for your time,
Kristofer Hoch

Replies are listed 'Best First'.
Re: Desperatly seeking CSW (Class::Std Wisdom)
by stvn (Monsignor) on Aug 08, 2006 at 14:08 UTC

    Without a peice of code which exhibits the issue, it is hard to say what exactly is causing it. However, I can tell you that this error:

    Can't make anonymous subroutine cumulative at <blah>
    is coming from inside Class::Std (the &_find_sub routine to be exact) and is called from the &initialize method, which is called within the perl compiler's CHECK phase. Most of what it is doing here is building restricted (aka - protected), private, cummulative and anticumulative methods. From the code you show above, I see nothing related to these things, and I suspect it is being caused by some other bit of code.

    -stvn

      stvn,

      That is a good point. I can't believe I overlooked showing an example of the call that I am making.

      my $state_arguments = { 'form_data' => \%form_data }; my $state_manager = My::Class->new($state_arguments); my $welcome_handler = { 'trigger' => 'welcome', 'handler' => 'Handler::Welcome', }; $state_manager->register_handler($welcome_handler);
      That is when I get the error message.

        I am not getting the same error when I run this code:

        Which seems to confirm my suspicion that the problem is elsewhere in your class. The error you are tripping in Class::Std is in one of the (IMHO) darker corners of the module. Something as simple as what you have demonstrated in the OP should not be causing that error. Perhaps if you posted your entire class, the issue might be more obvious to spot.

        -stvn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://566149]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-25 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found