Re: OOB and dispatch table
Shlomi Fish wrote: On Saturday 31 Oct 2009 02:38:11 Steve Bertrand wrote: Steve Bertrand wrote: 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 }, ); This should probably be: (untested) plan_by_id = sub { return $self-_find_plan_by_id(@_); }, See: * http://perl-begin.org/tutorials/perl-for-newbies/part3/#page-- refs_to_funcs--DIR (Sorry for the broken URL) No problem. * http://www.shlomifish.org/lecture/Perl/Newbies/lecture3/refs_to_funcs/ (Same resource - only as multiple pages). # ...obj passed in implicitly as expected $find_commands{ $find_this }( $search_data ); This should be: {{{ $find_commands{$find_this}-($search_data) }}} Beautiful! Even before I review your referenced document, I can already see the fundamental mistakes I was making, and why I was mentally making them. Thanks Shlomi, Steve -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: OOB and dispatch table
John W. Krahn wrote: Steve Bertrand wrote: Hi all, [ huge snip ] ...or any variant of trying to use the method-call syntax within a dispatch table coderef. How and where is _find_plan_by_id() defined? It's defined within its own class ( ie: file/package scope). The definition is standard, afaict. This is a 'private' function that I've intend to have only other methods within the class call. There are no prototypes, and the functions first order is to shift off self. Within the 'private' function, it generates an object from a different class, and performs operations with it. Essentially, it's an attempt to create a hierarchy whereby I can minimize calls to external objects to a select few internal methods of the class. Eventually, I'll push to have the original 'perform_find()' work with different requests and callbacks to be more flexible. fwiw. Here is the function (internal sanity and control structures removed): sub _find_plan_by_id { my $self= shift; my $search_data = shift; my $client = ISP::User-new(); # for the astute readers, I'm just learning how to structure # my classes to allow me to bypass the obj creation when a # class method call will do. # perltoot perltooc are becoming nearly comprehensible... my $plan= $client-get_plan( $search_data ); my $username = $plan-{ username }; $self-session-param( username = $username ); $self-session-param( planid = $search_data ); $self-forward( 'show_plan' ); } Steve -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: OOB and dispatch table
On Saturday 31 Oct 2009 02:38:11 Steve Bertrand wrote: Steve Bertrand wrote: 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 }, ); This should probably be: (untested) plan_by_id = sub { return $self-_find_plan_by_id(@_); }, See: * http://perl-begin.org/tutorials/perl-for-newbies/part3/#page-- refs_to_funcs--DIR (Sorry for the broken URL) * http://www.shlomifish.org/lecture/Perl/Newbies/lecture3/refs_to_funcs/ (Same resource - only as multiple pages). # ...obj passed in implicitly as expected $find_commands{ $find_this }( $search_data ); This should be: {{{ $find_commands{$find_this}-($search_data) }}} Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ The Human Hacking Field Guide - http://shlom.in/hhfg Chuck Norris read the entire English Wikipedia in 24 hours. Twice. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
OOB and dispatch table
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 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: OOB and dispatch table
Steve Bertrand wrote: 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. I suppose I should have actually asked a question ;) Can anyone point out what I am missing? Steve -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: OOB and dispatch table
Steve Bertrand wrote: Steve Bertrand wrote: 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 ); { $find_commands{ $find_this } }( $search_data ); } __END__ ...or any variant of trying to use the method-call syntax within a dispatch table coderef. I suppose I should have actually asked a question ;) Can anyone point out what I am missing? Steve -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: OOB and dispatch table
Shawn H Corey wrote: 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 ); { $find_commands{ $find_this } }( $search_data ); Thanks Shawn, but this did not work. I even made numerous modifications to the table entry and the call, but the result is the same ( $self is not passed in ). It works the way I have it... I'm just curious to know how to use the method call syntax on the right-side of a dispatch table entry successfully :) Cheers, Steve -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: OOB and dispatch table
Steve Bertrand wrote: Hi all, Hello, 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. How and where is _find_plan_by_id() defined? John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity. -- Damian Conway -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/