#!/usr/bin/perl -w $VERSION = 0.1; package Tk; # evil trick: implement with Glib the bits if Tk that Term::ReadLine::Gnu # tries to use, so we can run a Glib main loop while readline is looking for # chars. use strict; use Glib qw(TRUE); sub DoOneEvent { Glib::MainContext->iteration ($_[0]); } sub tkwait { warn "tkwait called @_" } sub fileevent { my ($class, $fh, $type, $callback) = @_; Glib::IO->add_watch (fileno $fh, 'in', sub { my ($fileno, $condition, $fh) = @_; $callback->($fh); return TRUE; }, $fh); } package main; use Term::ReadLine; # so we can get chars from the user with history. use Gtk2 -init; # initialized for the user's pleasure. use Data::Dumper; # it's handy to have. # tell readline to run a "Tk" mainloop while reading chars from the user. $Term::ReadLine::toloop++; my $term = new Term::ReadLine 'Gtk2-perl Interactive SHell'; my $prompt = "gish: "; my $OUT = $term->OUT || \*STDOUT; while (defined ($_ = $term->readline($prompt))) { no strict; # in initial testing, things didn't work well in the shell # if strict was on in here. my $res = eval($_); warn $@ if $@; print $OUT $res, "\n" if defined($res) and not $@; $term->addhistory($_) if /\S/; } =head1 NAME gish - Gtk2-perl Interactive SHell =head1 SYNOPSIS homie:~$ gish gish: $window = Gtk2::Window->new; Gtk2::Window=HASH(0x845b028) gish: $window->show_all gish: # at this point, the window is on the screen gish: $button = Gtk2::Button->new ("click me!") Gtk2::Button=HASH(0x8470fec) gish: $window->add ($button) gish: $button->show; gish: # now the button is visible inside the window gish: # but clicking it does nothing. gish: $button->signal_connect (clicked => sub {print "hi!\n"}) 8 gish: # and i will now click the button a few times... gish: hi! hi! hi! gish: $button->signal_handler_disconnect (8) gish: # and now when i click the button, nothing happens. gish: exit homie:~$ =head1 DESCRIPTION C is a gtk2-perl interactive shell, letting you play around with Gtk2 objects, data structures, and code in an interactive setting. It was inspired by wish, the simple windowing shell provided with Tk, in that you can build up live objects. This initial implementation is dead simple; it reads input lines from you using Term::ReadLine, and Cs those lines in the Perl interpreter. A main loop is always running, and the Gtk2 and Data::Dumper modules are imported for you. Basically, the main advantage of gish over the perl debugger is the integration with the Glib/Gtk2 event loop. =head1 SEE ALSO Gtk2(3pm), Data::Dumper(3pm), perl(1), wish(1), http://gtk2-perl.sourceforge.net =head1 BUGS Most bugs are actually missing features: No custom completions, e.g., Gtk2::Win should finish typing "Gtk2::Window" for you. No tracking of variables that you've created. You can easily mess things up. No way to save scripts, etc. =head1 AUTHOR muppet =cut