up
Perl Lecture Notes - May 4, 2002
- Coming Attractions - XML and lots of other acronyms
- XML processing :
- roll-your-own using regexps
- CPAN modules, SAX/DOM, files/streams
- connecting XML with SQL and relational-databases
- overview of other XML CPAN modules
- AxKit : XML to HTML content conversion within apache mod_perl
- SOAP-Lite : remote procedure calls in an XML format
- server performance and benchmarking (?)
- perhaps other Perl specifics, like Perl6 and parrot
- other topics?
- Today - perl GUI and yet another server/client database
- Why look a Graphical User application at all in a network course?
- Answer 1 - It's a cool thing you can do with perl.
- Answer 2 - Such applications can be a nice implement server backend
admininstration tool, or even network client tool. Especially
when they're not all that hard to write.
- Perl/Tk
- based on Tcl/Tk , an open source language / window tool kit
- library of window widgets to create GUI on unix and
Microsoft Windows (see ActiveState's site).
- Installation:
perl -MCPAN -e shell; force install Tk
or similar with ActiveState's "ppm" command on MSWindows
- Originally written for X (X11) windows, and that's the way
I'll show it here. In that environment, you can have
the windows pop up on a remote machine, either by
- setting an ENV variable, i.e. DISPLAY=your.machine.com:0.0
(which isn't working under ssh on bob right now), or
- invoking the application with " ./script -display your.machine.com:0.0"
on the command line.
(You may also have to config your machine with an "xhost +remote.ip.com" command
or the equivalent to authorize the remote X server to pop up
windows on your terminal. Typically you only need do this once.)
- Note that you do *not* need X11 to run this on
MSWindows - you only need X11 if you want to run remote
applications as GUI's on your local machine. See for example
http://sources.redhat.com/win32-x11/ - an x11 windows thing
on win32.
- To see if X is working,
type "xclock -display your.machine.com:0.0"
at the command line.
- Trivial example: Hello World
- commandline: tk/xHello -display your.machine.com:0.0
- source
- Basic ideas:
- GUI is made up of "widgets"
(buttons, labels, textboxes, frames)
- widgets include Frames which contain other widgets
- outermost is "MainWindow"; all others created from this
- very similar to Java SWING stuff and other GUI frameworks
- each widget is places spacially with a layout manager
using "pack", "grid", or "place" methods.
- all methods take -option=>value pairs to define
their characterstics.
- There are *many* various widgets, options, and methods.
- All have $widget->configure(-option=>value)
method to change things.
- Most of the calls return the object, so you can
often (if you like) chain the method calls:
$mainwindow->Button()->pack()
rather than
$b=$mainwind->Button; $b->pack;
- Typically the widgets do things by
either
(1) callback subroutines and/or
(2) perl variables bound to their internal values
- (Note: this "callback" method of programming
is also what is used in typical XML stream processing...)
- Examples:
- xTimer (source)
- widget (installed as /usr/bin/widget as part of Perl/Tk)
- bouncing balls
- Gedi text editor
- browse through others
- ptkdb - a graphical interface to the debugger (Devel::ptkdb)
see files in ptkdb directory
- a bit about LDAP and how to call it from Perl
- A specialized server/client database
optimized reading and searching.
- Structure is a tree of "Entries", each with various attributes.
- Tuned to give quick response to high-volume lookup.
- Authentication and database replication supported.
(Though not trivial to turn on...)
- Commonly used for something like an organization's user database.
- config file and schema define "attributes" (properties of an entry) and
"classes" (template of which attributes an entry may or must have)
- These are worldwide, standard definitions - and they're pretty persickity.
- pictures of LDAP trees
- Installation notes and some config files on bob
- Net::LDAP is one of a number of perl CPAN modules that
query and change LDAP directories.
- Installation: perl -MCPAN -e shell; install Bundle::Net::LDAP
- Pretty straightforward perl objects and methods; see examples and resources
- some perl scripts
- add a person to the database - source
- search the database - source
- LDAP can be (and is) used for site-wide authentication and similar tasks.
- BTW, here's a java GUI tool for browsing and editing LDAP trees
- Resources / Documentation
- Assignmnent
- Read about Perl/Tk and LDAP from the links above.
- Write a perl GUI applet that displays users and emails from the LDAP user database on bob.
- If time allows and the spirit moves you, teach it to edit and add entries, too.
- You may do this entirely on the grad center linux boxes and/or bob,
or you can install Perl/Tk on a home machine and run the GUI application
as a client that connects across the net to bob.
Welcome back.