home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeMastering Perl/TkSearch this book

21.3. Building and Testing Tk::Square

Once all the files are in place, we simply run:

% perl Makefile.PL

which generates the topmost Makefile as well as pTk/Makefile. Then a simple make munges pTk/mTk/generic/tkSquare.c, compiles the munged pTk/tkSquare.c, runs xsubpp on Square.xs, and then compiles the generated Square.c file and links the .o files into a single .so loadable (for Unix). The autosplit subroutines, the Square.pm file, and the loadable are all copied into blib, the build library, for testing.

21.3.1. t/square_demo.t

Here's the test program. It's a rather normal Perl/Tk program with a few special-purpose print statements. When we type make test, files in the t directory are executed, each of which prints out the number of tests and strings of the form "ok 1" or "not ok 2", specifying the status of each test. For related information, check out the Test::Harness module.

#!/usr/local/bin/perl -w

# This program creates Square widget.  The Square class
# has these default bindings:
# 
# <1> press/drag : moves the Square to the pointer
# "a"            : toggles size( ) animation on/off

BEGIN {
    $| = 1;
    print "1..3\n";
}

use Tk;
use Tk::Square;
use strict;

my $mw = MainWindow->new;
print "ok 1\n";

my $sq = $mw->Square;
print "ok 2\n";
$sq->pack(qw/-expand yes -fill both/);
$sq->focus;

MainLoop;
print "ok 3\n";


Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.