I finally got around to implementing the Tkx::Scrolled megawidget that
I'd been thinking about for a long while. In the process of doing so I
ran across some behavior regarding callbacks that I couldn't grok from
the documentation.

The basic case is straightforward enough:

  $text->configure(-yscrollcommand => [$scrollbar, 'set']);

This calls C<$scrollbar->set(first, last)> (where "first" and "last" are
the range of $text that's visible). I call this straightforward because
it's simple and matches the behavior of Perl/Tk, but I haven't seen this
syntax actually documented anywhere.

The next case is a little odd:

  $text->configure(-yscrollcommand => [\&_set, 'foo']);

This calls C<_set(first, last, 'foo')>. It seems odd to me that 'foo'
appears at the end rather than at the beginning. It's particularly
awkward if you want to pass an object because "$self" won't end up being
the first argument to the method. This append vs. prepend behavior
doesn't appear to be documented.

The weirdest case is this one:

  $text->configure(-yscrollcommand => \&_set);

If I dump @_ in _set() I get this:

  $VAR1 = [
    undef,
    bless( do{\(my $o = 58361464)}, 'Tcl' ),
    '::perl::CODE(0x37c7cdc)',
    '0',
    '1'
  ];

Here the first/last values appear at the end. The second argument
appears to be the Tcl interpreter (from Tcl.pm). The third argument is
some sort of blessed reference to the subroutine being called, although
the stringification is unusual. I have no idea why there's a leading
undef value, or what it's supposed to be a placeholder for. The
documentation only states that you can pass a CODE reference to a
callback. It says nothing about what the arguments are.

I'm hoping for a little enlightenment. If someone can explain the
behavior I might even be motivated to submit a documentation patch.

-mjc

Reply via email to