in reply to Re^2: Inotify2 + AnyEvent (naked code ref)
in thread Inotify2 + AnyEvent

I know you are smarter than me about this stuff, but even without adding (time), to the coderef
# -command => \&callback(time), -command => \&callback,
still executes the sub callback at button creation time, causing a pre-mature exit, and crash.

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^4: Inotify2 + AnyEvent (naked code ref)
by tye (Sage) on Oct 05, 2011 at 21:05 UTC

    I'm not going to install Tk at the moment. But, \&callback does not call callback() (it just provides a code ref):

    $ perl -le 'sub callback { die "called( @_ )!" } print \&callback' CODE(0x219b4c0) $ perl -le 'sub callback { die "called( @_ )!" } print \&callback("ar +g")' called( arg )! at -e line 1. $

    The Tk::Button documentation (see also Tk::callbacks) implies that -command => $codeRef will not immediately call the referenced sub.

    There certainly could be other reasons for that usage to cause "pre-mature exit and crash". For example, -command => \&callback, time, would likely "crash".

    I see plenty of evidence to suggest that it will not cause callback() to be called at button-creation time and no details suggesting that you have enough evidence to support that one part of your claim.

    - tye        

      I'm not going to install Tk at the moment.

      Ok, thanks for explaining. It's the () that causes premature exiting.

      #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow; $mw->geometry("400x200"); my $button = $mw->Button(-text => "Sub test exit", -command => \&callback(), # exits prematurely # -command => \&callback, # works ok )->pack(); MainLoop; sub callback{ print "exiting\n"; Tk::exit; } __END__

      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh
        $ perl -MO=Deparse -e " $foo = \&bar " $foo = \&bar; -e syntax OK $ perl -MO=Deparse -e " $foo = \&bar() " $foo = \(&bar()); -e syntax OK