How Not to Port Tk::Square

As we learned earlier, it’s best to keep private C widgets distinct from the Perl/Tk distribution. But if we were to do a merge, here are some considerations.

First, copy tkSquare.c (with the same hand edits described previously) to pTk/mTk/generic, copy square_demo.t to t, and then fire up your favorite editor and add these lines to the main Perl/Tk MANIFEST:

Square/Makefile.PL
Square/Square.xs 
Square/Square.pm
pTk/mTk/generic/tkSquare.c
t/square_demo.t

Now make the Square directory and populate it with the preceding files. The files Square.xs and Square.pm are the exact same files we just used, but Makefile.PL looks like this:

use Tk::MMutil;
Tk::MMutil::TkExtMakefile(
    'dynamic_ptk' => 1
);

Secondly, we must add a single statement to three files so the Perl/Tk core is “aware of” Tk_SquareCmd.

To pTk/mTk/generic/tk.h, add the followingaround line 1880:

EXTERN int Tk_SquareCmd _ANSI_ARGS_((ClientData clientData,
        Tcl_Interp *interp, int argc, char **argv));

To pTk/mTk/generic/tkWindow.c, add the following around line 152:

{"square",        Tk_SquareCmd,         NULL,              1},

To pTk/tk.exc,add the following around line 96:

Tk_SquareCmd

It may be advisable to start fresh and begin with:

make distclean
perl Makefile.PL

Making and testing the widget code is similar to what we just did, although development is slower because it’s a make from the top of the entire Perl/Tk hierarchy, with scores of dependencies and nested makes. You’ll quickly find that the make; make test cycle is ridiculously ...

Get Mastering Perl/Tk now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.