O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required