Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Dear monks,

when I use -validate with Tk::Entry, I get unexpected behaviour in combination with -textvariable and changing the variable. For this example, I used a button to change the variable $entryText which should succeed until the value of 3 and fail for bigger values.

#! /usr/bin/perl use warnings; use strict; use Tk; my $entryText = 1; print "Perl-Version: $]\nTk-Version: $Tk::VERSION\n"; my $mw = MainWindow->new(); my $entry = $mw->Entry( -textvariable => \$entryText, -validate => 'all', -validatecommand => \&ValidateCmd, ) ->pack( -side => 'left' ); $mw->Button( -text => 'increase', -command => sub { $entryText++ }, ) ->pack( -side => 'right' ); MainLoop; sub ValidateCmd { my( $newValue ) = @_; { local $" = '] ['; no warnings 'uninitialized'; print "ARGS: [@_]\n"; } # return error if value > 3 and don't change the content if( $newValue > 3 ) { print "Error: Too big: $newValue\n"; return 0; } # if return 1; } # ValidateCmd

With Perl 5.008008 and Tk 804.024:

Perl-Version: 5.008003 Tk-Version: 800.024 ARGS: [1] [] [] [-1] [-1] ARGS: [2] [] [1] [-1] [-1] ARGS: [3] [] [2] [-1] [-1] ARGS: [4] [] [3] [-1] [-1] Error: Too big: 4 ARGS: [4] [] [3] [-1] [-1] Error: Too big: 4 ARGS: [4] [] [3] [-1] [-1] Error: Too big: 4

everything works fine, but with Perl-Versions >= 5.008008 and Tk Version 800.027 the validation stops when the first 0 is returned and so bigger values than 3 can be inserted via $entryText:

Perl-Version: 5.008008 Tk-Version: 804.027 ARGS: [1] [] [] [-1] [6] ARGS: [2] [] [1] [-1] [6] ARGS: [3] [] [2] [-1] [6] ARGS: [4] [] [3] [-1] [6] Error: Too big: 4

and the variable may become bigger than 3 since the validation stops. Additionally, the interface of validatecommand is changed (-1 vs. 6 for the same type of action which could break a lot of existing apps).

From perldoc Tk::Entry:

The validateCommand will turn itself off by setting validate to none when an error occurs, for example when the validateCommand or invalidCommand encounters an error in its script while evaluating, or validateCommand does not return a valid boolean value.

But returning 0 (or undef or nothing) is no error in my eyes.

Is this a bug, or am I the bug?

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8."

In reply to Bug: Tk::Entry 804.027 validate? by strat

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [erix]: then you might as well send that patch to the DBIC guys :)
    [Corion]: erix: Yeah, I just found that it has no documentation at all on how to circumvent/ eliminate "1+n SELECTs" by building a local hash... I guess I have to make ->has_many do the hash lookup instead of doing the SQL query. But as the problem ...
    [Corion]: ... has only manifested itself so far through the puzzled questions of other bystanders, I won't go deeper at this time. But the DBIx::Class documentation could well do with a document on how to make "it" (that is, ORMs in general) faster ;)
    [Corion]: I find that DBIx::Class, like most ORMs makes things easy until they become performance critical and then makes it horribly hard to change things because the design is highly inflexible if you don't already know about the problems of 1+n :-/
    [choroba]: that's why I don't like similar libraries. They pretend you don't have to learn SQL, but in the end, you have to learn how SQL plus to overcome their own limitations
    [Corion]: "Just write the proper SQL beforehand" is of course the appropriate solution, but if you did that, you wouldn't/couldn't use DBIx::Class either. At least not in an obvious (to me) way.
    choroba scratches a "how"

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (7)
    As of 2017-09-25 11:06 GMT
    Find Nodes?
      Voting Booth?
      During the recent solar eclipse, I:

      Results (279 votes). Check out past polls.