Debian Codegraph @

lib/Tk/bindDump.pm.save

raw
1 $Tk::bindDump::VERSION = '1.0';
2
3 package Tk::bindDump;
4
5 use Exporter;
6
7 use base qw/Exporter/;
8 @EXPORT = qw/bindDump/;
9 use strict;
10
11 sub bindDump {
12
13 # Dump lots of good binding information. This pretty-print subroutine
14 # is, essentially, the following code in disguise:
15 #
16 # print "Binding information for $w\n";
17 # foreach my $tag ($w->bindtags) {
18 # printf "\n Binding tag '$tag' has these bindings:\n";
19 # foreach my $binding ($w->bind($tag)) {
20 # printf " $binding\n";
21 # }
22 # }
23
24 my ($w) = @_;
25
26 my (@bindtags) = $w->bindtags;
27 my $digits = length( scalar @bindtags );
28 my ($spc1, $spc2) = ($digits + 33, $digits + 35);
29 my $format1 = "%${digits}d.";
30 my $format2 = ' ' x ($digits + 2);
31 my $n = 0;
32
33 print "\n## Binding information for '", $w->PathName, "', $w ##\n";
34
35 foreach my $tag (@bindtags) {
36 my (@bindings) = $w->bind($tag);
37 $n++; # count this bindtag
38
39 if ($#bindings == -1) {
40 printf "\n$format1 Binding tag '$tag' has no bindings.\n", $n;
41 } else {
42 printf "\n$format1 Binding tag '$tag' has these bindings:\n", $n;
43
44 foreach my $binding ( @bindings ) {
45 my $callback = $w->bind($tag, $binding);
46 printf "$format2%27s : %-40s\n", $binding, $callback;
47
48 if ($callback =~ /SCALAR/) {
49 if (ref $$callback) {
50 printf "%s %s\n", ' ' x $spc1, $$callback;
51 } else {
52 printf "%s '%s'\n", ' ' x $spc1, $$callback;
53 }
54 } elsif ($callback =~ /ARRAY/) {
55 if (ref $callback->[0]) {
56 printf "%s %s\n", ' ' x $spc1, $callback->[0], "\n";
57 } else {
58 printf "%s '%s'\n", ' ' x $spc1, $callback->[0], "\n";
59 }
60 foreach my $arg (@$callback[1 .. $#{@$callback}]) {
61 if (ref $arg) {
62 printf "%s %-40s", ' ' x $spc2, $arg;
63 } else {
64 printf "%s '%s'", ' ' x $spc2, $arg;
65 }
66
67 if (ref $arg eq 'Tk::Ev') {
68 if ($arg =~ /SCALAR/) {
69 print ": '$$arg'";
70 } else {
71 print ": '", join("' '", @$arg), "'";
72 }
73 }
74
75 print "\n";
76 } # forend callback arguments
77 } # ifend callback
78
79 } # forend all bindings for one tag
80
81 } # ifend have bindings
82
83 } # forend all tags
84 print "\n";
85
86 } # end bindDump
87
88 1;
89 __END__
90
91 =head1 NAME
92
93 Tk::bindDump - dump detailed binding information for a widget.
94
95 =head1 SYNOPSIS
96
97 use Tk::bindDump;
98
99 $splash->bindDump;
100
101 =head1 DESCRIPTION
102
103 This subroutine prints a widget's bindtags. For each binding tag it
104 prints all the bindings, comprised of the event descriptor and the
105 callback. Callback arguments are printed, and Tk::Ev objects are
106 expanded.
107
108 =head1 COPYRIGHT
109
110 Copyright (C) 2000 - 2001 Stephen O. Lidie. All rights reserved.
111
112 This program is free software; you can redistribute it and/or modify it under
113 the same terms as Perl itself.
114
115 =cut