From 4971610437daa682083c50ed20a18c9366f1c55d Mon Sep 17 00:00:00 2001 From: etienne Date: Wed, 18 Dec 2002 16:58:00 +0000 Subject: Hack pour se donner la possibilite de charger ZincDebug sans modifier le code, de la maniere suivante : perl -MZincDebug script.pl --- Perl/Zinc/Debug.pm | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) (limited to 'Perl') diff --git a/Perl/Zinc/Debug.pm b/Perl/Zinc/Debug.pm index e7c3909..8eb5ef3 100644 --- a/Perl/Zinc/Debug.pm +++ b/Perl/Zinc/Debug.pm @@ -1,6 +1,7 @@ # ZincDebug Perl Module : # -# For debugging/analysing a Zinc application +# For debugging/analysing a Zinc application. Only one instance +# of zinc can be managed. # # Author : Daniel Etienne # @@ -9,7 +10,7 @@ package ZincDebug; use strict 'vars'; -use vars qw(@ISA @EXPORT $WARNING); +use vars qw(@ISA @EXPORT @EXPORT_OK $WARNING); use Carp; use English; require Exporter; @@ -24,6 +25,7 @@ use Tk::ItemStyle; @ISA = qw(Exporter); @EXPORT = qw(finditems snapshot tree); +@EXPORT_OK = qw(finditems snapshot tree); my ($help_tl0, $help_tl, $result_tl, $result_fm, $search_tl, $searchtree_tl, $showitemflag); @@ -49,6 +51,50 @@ my $helptree_tl; my $wwidth; my $wheight; + +# Hack to capture $zinc symbols. +# Usefull to load ZincDebug by running your perl script in this way : +# perl -MZincdebug yourscript.pl +# or +# perl -MZincDebug=tree,finditems yourscript.pl +# +# Needs that zinc instance appears in the symbols table of main package, +# i.e. zinc instance is defined in you script as global (not lexical) +# variable +# +sub import { + my ($module, @args) = @_; + # export_to_level really export symbols + ZincDebug->export_to_level(1, @_); + my %args; + my $noargs = 1 unless @args > 0; + for (@args) { + $args{$_} = 1; + } + Tk::after(3000, sub { + my $found = 0; + # return if $zinc is alrealdy defined, by invocation of ZincDebug + # functions tree(), finditems()... in main + return if $zinc; + for my $name (keys %{'main::'}) { + if (ref(${$main::{$name}}) eq 'Tk::Zinc') { + &tree(${$main::{$name}}) if $args{tree} or $noargs; + &finditems(${$main::{$name}}) if $args{finditems} or $noargs; + &snapshot(${$main::{$name}}) if $args{snapshot} or $noargs; + $found++; + # return when first instance of Zinc is found + return; + } + } + if ($found == 0) { + print "in ZincDebug module, no zinc instance has been detected at ". + "runtime.\n"; + } + }); + +} # end import + + sub tree { &setwidget(shift); @@ -1456,12 +1502,17 @@ ZincDebug - a perl module for analysing a Zinc application. =head1 SYNOPSIS + perl -MZincDebug zincapplication.pl + + or + use ZincDebug; my $zinc = MainWindow->new()->Zinc()->pack; finditems($zinc); tree($zinc); snapshot($zinc); + =head1 DESCRIPTION ZincDebug provides an interface to help developers to debug or analyse Zinc applications. @@ -1474,7 +1525,9 @@ With B function, you are able to snapshot the application window, in o Press B key in the main window of the application to have some help about available input sequences. - +If you load ZincDebug using the -M perl option, no code modification is needed but the functions described above are invoked with default configuration. + + =head1 FUNCTIONS @@ -1553,6 +1606,10 @@ Defines the basename used for the file containing the snaphshot. The filename wi =back +=head1 LIMITATIONS + +ZincDebug is currently able to manage only one zinc instance. + =head1 AUTEURS Daniel Etienne -- cgit v1.1