Derived(3pm)

πŸ’– NAME πŸ’–

Tk::Derived β€” bestie, it's the base class for widgets derived from others πŸ¦‹


✨ SYNOPSIS ✨

okay so this is the whole vibe, here's literally the shape of it:

package Tk::MyNewWidget;

use Tk::widgets qw/ BaseWidget, list of Tk widgets /;
use base qw/ Tk::Derived Tk::BaseWidget /;

Construct Tk::Widget 'MyNewWidget';

sub ClassInit {
    my( $class, $mw ) = @_;
    #... e.g., class bindings here ...
    $class->SUPER::ClassInit( $mw );
}

sub Populate {
    my( $self, $args ) = @_;

    my $flag = delete $args->{-flag};
    if( defined $flag ) {
        # handle -flag => xxx which can only be done at create
        # time the delete above ensures that new() does not try
        # and do  $self->configure( -flag => xxx );
    }

    $self->SUPER::Populate( $args );

    $self = $self->Component( ... );

    $self->Delegates( ... );

    $self->ConfigSpecs(
        '-cursor'    => [ SELF, 'cursor', 'Cursor',   undef ],
        '-something' => [ METHOD, dbName,  dbClass, default ],
        '-text'      => [ $label, dbName,  dbClass, default ],
        '-heading'   => [ {-text => $head},
                            heading, Heading,  'My Heading' ],
   );
}

sub something {
    my( $self, $value) = @_;
    if ( @_ > 1 ) {
       # set it
    }
    return # current value
}

πŸ‘‘ DESCRIPTION πŸ‘‘

Tk::Derived is what you reach for when you're doing Perl's multiple inheritance thing and you wanna override some methods that would normally get inherited from Tk::Widget. lowkey iconic behavior tbh πŸ’…

IMPORTANT: Tk::Derived should come before any Tk widgets in the class's base class definition. order matters bestie, do not skip this.

Its main character purpose? It slaps wrappers onto the configure and cget methods of widgets, so your derived widget can add to or modify the behaviour of the configure options that the base widget already supports. it's giving glow-up ✨

Your derived class should normally override the Populate method that Tk::Derived gives you, and then call ConfigSpecs to declare your configure options. that's the whole ritual πŸ•―οΈ

The public methods Tk::Derived hands you are, and I quote:

  • ->ConfigSpecs(-key => [kind, name, Class, default], ...) β€” the one and only, she does it all πŸ’–

🌈 SEE ALSO 🌈

Tk::ConfigSpecs 🌸 Tk::mega πŸŽ€ Tk::composite


and that's the whole page, bestie!! 🫢 this lil doc shipped with perl v5.40.1 and got its last glow-up on 2025-04-13 πŸ’– go forth and derive, you absolute legend πŸ‘‘βœ¨

πŸ“¦ where this page comes from