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

Re: Tkx after coderef problem

by huck (Parson)
on Jun 02, 2018 at 18:49 UTC ( #1215757=note: print w/replies, xml ) Need Help??


in reply to Tkx after coderef problem

I have also discovered that the following syntax also works.

sub accept_out_cclose_after { my $tkxfsr=shift; my $afterid=shift; my $delay=shift; my $send_id; if ($esub==1) { $send_id=Tkx::after( $delay , sub{&{$tkxfsr->{aft +er}{$afterid}{sub}}()});} elsif ($esub==2) { $send_id=Tkx::after( $delay , [$tkxfsr->{after}{$ +afterid}{sub}] );} else { $send_id=Tkx::after( $delay , $tkxfsr->{aft +er}{$afterid}{sub} ); } $tkxfsr->{after}{$afterid}{eventid}=$send_id; $tkxfsr->{after}{$afterid}{delay}=$delay; }
perl huh-after.pl -esub 2
And i suspect that the [] notation in the Tkx::after call is doing the same thing i did with the sub {}, creating a one use anonymous subroutine reference.

Replies are listed 'Best First'.
Re^2: Tkx after coderef problem
by Anonymous Monk on Jun 02, 2018 at 20:42 UTC

    >>And i suspect that the [] notation in the Tkx::after call is doing the same thing i did with the sub {}, creating a one use anonymous subroutine reference.

    no it doesnt create an anonymous sub it doesnt need to

      Sorry, yes it does. Found it!

      https://github.com/gisle/tcl.pm/blob/master/Tcl.pm lines 502-518

      elsif ($ref eq 'ARRAY' && ref($arg->[0]) eq 'CODE') { # We have been passed something like [\&subroutine, $arg1, ...] # Create a proc in Tcl that invokes this subroutine with args my $events; # Look for Tcl::Ev objects as the first arg - these must be # passed through for Tcl to evaluate. Used primarily for %-subs # This could check for any arg ref being Tcl::Ev obj, but it # currently doesn't. if ($#$arg >= 1 && ref($arg->[1]) eq 'Tcl::Ev') { $events = splice(@$arg, 1, 1); } $args[$argcnt] = $interp->create_tcl_sub(sub { $arg->[0]->(@_, @$arg[1..$#$arg]); }, $events, undef, $current_r); push @codes, $anon_refs{$current_r}; }
      Notice how lines 514-516 create a **perl** anon-sub

      Sorry, better luck next time!

      "no it doesnt create an anonymous sub it doesnt need to

      If you are so sure of that then prove it, show me a link to the arrayref processing of Tkx:after calls, or tell me where to look for the code. Till then my thought that processing of a arrayref in the callback position creates a single use anon-coderef still holds as it explains why that call method works, like the the sub{...} method does, but the static coderef fails. (well at least on unix).

      There is deep autoload magic going on in Tkx that i still dont understand and i have yet to find out where the parameter munging actually takes place to move across the perl<->Tk/Tcl boundary. Ive even tried to look for it.

        Not going to prove anythung or fix typos. It doesnt need to create a subrkutine to be able to call a subroutine and pass arguments to it.Why would it . calling a subroutine is identical no matter a who creates it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1215757]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2019-10-16 22:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?