Tk::Derived - Base class for widgets derived from others
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 }
User Contributed Perl Documentation Derived(3) NAME Tk::Derived - Base class for widgets derived from others SYNOPSIS 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 used with Perl's multiple inheritance to override some methods normally inherited from Tk::Widget. Tk::Derived should precede any Tk widgets in the class's base class definition. Tk::Derived's main purpose is to apply wrappers to "configure" and "cget" methods of widgets to allow the derived widget to add to or modify behaviour of the configure options supported by the base widget. The derived class should normally override the "Populate" method provided by Tk::Derived and call "ConfigSpecs" to declare configure options. The public methods provided by Tk::Derived are as follows: ->ConfigSpecs(-key => [kind, name, Class, default], ...) ATTRIBUTES See attributes(7) for descriptions of the following attributes: +---------------+----------------------------+ |ATTRIBUTE TYPE | ATTRIBUTE VALUE | +---------------+----------------------------+ |Availability | library/perl-5/perl-tk-532 | +---------------+----------------------------+ |Stability | Volatile | +---------------+----------------------------+ SEE ALSO Tk::ConfigSpecs Tk::mega Tk::composite NOTES Source code for open source software components in Oracle Solaris can be found at https://www.oracle.com/downloads/opensource/solaris-source- code-downloads.html. This software was built from source available at https://github.com/oracle/solaris-userland. The original community source was downloaded from http://search.cpan.org/CPAN/authors/id/S/SR/SREZIC/Tk-804.036.tar.gz. Further information about this software can be found on the open source community website at http://search.cpan.org/~srezic/Tk. perl v5.32.0 2013-11-15 Derived(3)