On Tue, Apr 15, 2014 at 2:56 AM, tsuyoshi okita <825...@gmail.com> wrote:

> *** unhandled exception in callback:
> ***   Can't call method "get_text" on an undefined value at ./switch.plline 
> 28.
>

This call to get_text() is in the closure for the "changed" signal.
The problem is $count: $count is a "free" variable wrt sub { ... }, i.e.
$count is defined outside the sub's lexical scope.
But $count is defined in file scope and when the signal is emitted, its
value is 2!
Hence the code executed is actually

   warn "You've entered: ", ${ "entry_2" }->get_text();

In your later post, you avoided this problem

        ${ "entry_" . $count }->signal_connect(
            'changed' =>  \&enter_get_text_calling,  \${ "entry_" . $count
});

Now the "changed" closure (closure in the GObject sense) is a simple Perl
sub (not using any free variables).
And the "data" argument (\${ "entry_" . $count }) to signal_connect is now
evaluated at the time signal_connect() is called, hence uses the same value
of $count as for the invocant of signal_connect().

Cheers, Roderich
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to