Tie::Wx::Widget - get&set main value of a Wx widget with less syntax and more magic


    use Tie::Wx::Widget;

    tie $tiedwidget, Tie::Wx::Widget, $widget;

    $tiedwidget = 7;       # instead of $widgetref->SetValue(7);

    say $tiedwidget;       # instead of say $widgetref->GetValue;

    untie $tiedwidget;     # now $tiedwidget is a normal scalar again (not required)


Often are the widget values coupled with each other. For instance in
App::Spirograph is a slider, which max value is the value of another slider.
Once you know this, why keep track of it and change the range by hand 
any given time?

    tie $tslider, Tie::Wx::Widget, $slider, 
        sub { $[0]->SetValue($[1]); $subslider->SetRange(1, $[1]) };

The first parameter to the callback is always the Wx object reference,
the assign-callback gets also a second with the assigned value.
Own callbacks replace the the ones, generated by default.

The complete parameter list is is:

    tie $tw, Tie::Wx::Widget, $widget, [&$do_when_assign, &$do_when_retrieve];

Yes, its also doable with events, but thats also more syntax than this.
Plus, its a different event for many widgets, why remember this?
Plus, a tied widget still gives you the freedom to change the value
under the radar. See section INTERNALS for more.


Your program will C<die>, if you don't provide a proper Wx widget,
that has a GetValue and SetValue method, or the callbacks are no coderef.
Unless you init with:

    use Tie::Wx::Widget 'warn_mode';

or do later:


Then will be called C<warn> instead of C<die>. 
But you can switch anytime back with:


Wich has only effect for all variables tied afterwards.
Because if the Wx ref is not good, there will be no tying anyway.


    # how to get a reference to the Tie::Wx::Widget object ?
    $tieobject = tie $tiedwidget, Tie::Wx::Widget, $widget;
    $tieobject = tied $tiedwidget;

    # now you even can:
    # aka:
    # or do any other method on the wx object
    # works too  (hides the widget)

    # doesn't do anything


To install this module, run the following commands:

    perl Makefile.PL
    make test
    make install


After installing, you can find documentation for this module with the
perldoc command.

    perldoc Tie::Wx::Widget

You can also look for information at:

    RT, CPAN's request tracker (report bugs here)

    AnnoCPAN, Annotated CPAN documentation

    CPAN Ratings

    Search CPAN

    Source Repository:


Copyright (C) 2011 Herbert Breunung

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See for more information.