develooper Front page | perl.beginners | Postings from October 2009

OOB and dispatch table

Thread Next
From:
Steve Bertrand
Date:
October 30, 2009 17:28
Subject:
OOB and dispatch table
Message ID:
4AEB84C2.1040201@ibctech.ca
Hi all,

Within a CGI environment, I'm trying to do a dispatch table test, but
can't figure out how to call the coderef as a method. Here is the
working code. I'll describe what doesn't work afterwards:

sub perform_find {

    my $self    = shift;

    my $find_this   = $self->query->param( 'find_this' );
    my $search_data = $self->query->param( 'search_data' );

    my %find_commands = (

# call by local function
                plan_by_id  => \&_find_plan_by_id,
            );

# and pass in $self explicitly
    $find_commands{ $find_this }( $self, $search_data );
}

__END__

Things progress properly using the above. What I don't understand, is
why I have to pass in $self as a param to the dispatch table. What
didn't work is this:


sub perform_find {

    my $self    = shift;

    my $find_this   = $self->query->param( 'find_this' );
    my $search_data = $self->query->param( 'search_data' );

    my %find_commands = (

# I'm trying to call the method on myself
                plan_by_id  => \&{ $self->_find_plan_by_id },
            );

# ...obj passed in implicitly as expected
    $find_commands{ $find_this }( $search_data );
}

__END__

...or any variant of trying to use the method-call syntax within a
dispatch table coderef.

Steve

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About