aboutsummaryrefslogtreecommitdiff
path: root/Perl/Zinc
diff options
context:
space:
mode:
authormertz2003-11-07 15:36:50 +0000
committermertz2003-11-07 15:36:50 +0000
commit25225610627298db1bb70e3b7d296c7ce848d6ae (patch)
tree5e7761eb18c79d4d8de9c153233cb059e6d1db83 /Perl/Zinc
parentfc6b9897872007d57a2145e5d07d90f7e5305a0a (diff)
downloadtkzinc-25225610627298db1bb70e3b7d296c7ce848d6ae.zip
tkzinc-25225610627298db1bb70e3b7d296c7ce848d6ae.tar.gz
tkzinc-25225610627298db1bb70e3b7d296c7ce848d6ae.tar.bz2
tkzinc-25225610627298db1bb70e3b7d296c7ce848d6ae.tar.xz
Slight modifications to even better display zinc methods calls as code
and addition of some tests
Diffstat (limited to 'Perl/Zinc')
-rw-r--r--Perl/Zinc/TraceUtils.pm134
1 files changed, 91 insertions, 43 deletions
diff --git a/Perl/Zinc/TraceUtils.pm b/Perl/Zinc/TraceUtils.pm
index 55714f9..5a9536f 100644
--- a/Perl/Zinc/TraceUtils.pm
+++ b/Perl/Zinc/TraceUtils.pm
@@ -8,84 +8,132 @@ use strict;
use Tk::Font;
use Tk::Photo;
use vars qw(@EXPORT);
-@EXPORT = qw(printItem printArray printList);
+@EXPORT = qw(printItem printArray printList Item Array List);
-### to print something
sub printItem {
+ print &Item (@_);
+}
+
+sub printArray {
+ print &Array (@_);
+}
+
+sub printList {
+ print &List (@_);
+}
+
+sub Item {
my ($value) = @_;
my $ref = ref($value);
# print "VALUE=$value REF=$ref\n";
if ($ref eq 'ARRAY') {
- printArray ( @{$value} );
- }
- elsif ($ref eq 'CODE') {
- print "{CODE}";
- }
- elsif ($ref eq 'Tk::Photo') {
+ return Array ( @{$value} );
+ } elsif ($ref eq 'CODE') {
+ return "{CODE}";
+ } elsif ($ref eq 'Tk::Photo') {
# print " **** $value ***** ";
- print "Tk::Photo(\"". scalar $value->cget('-file') . "\")";
- }
- elsif ($ref eq 'Tk::Font') {
- print "'$value'";
+ return "Tk::Photo(\"". scalar $value->cget('-file') . "\")";
+ } elsif ($ref eq 'Tk::Font') {
+ return "'$value'";
+ } elsif ($ref eq '') { # scalar
+ print "value: $value\n";
+ if (defined $value) {
+ print "defined value: $value\n";
+ { no strict;
+ if ($value eq eval ($value)) {
+ return $value;
+ } else {
+ return "'$value'";
+ }
+ use strict;
+ }
+ } else {
+ return "_undef";
+ }
+ } else { # some class instance
+ return $value;
}
- elsif ($ref eq '') { # scalar
+
+} # end Item
+
+### to print something
+sub Item {
+ my ($value) = @_;
+ my $ref = ref($value);
+# print "VALUE=$value REF=$ref\n";
+ if ($ref eq 'ARRAY') {
+ return Array ( @{$value} );
+ } elsif ($ref eq 'CODE') {
+ return "{CODE}";
+ } elsif ($ref eq 'Tk::Photo') {
+# print " **** $value ***** ";
+ return "Tk::Photo(\"". scalar $value->cget('-file') . "\")";
+ } elsif ($ref eq 'Tk::Font') {
+ return "'$value'";
+ } elsif ($ref eq '') { # scalar
if (defined $value) {
- if ($value eq '') {
- print "''";
- } elsif ($value =~ /\s/
+ if ($value =~ /^-?\d+(\.\d*(e[+-]?\d+)?)?$/ or # -1. or 1.0
+ $value =~ /^-[a-zA-Z]([\w])*$/ # -option1 or -option-1
+ ) {
+ return $value;
+ } elsif ($value eq ''
+ or $value =~ /\s/
or $value =~ /^[a-zA-Z]/
- or $value =~ /^[\W]$/ ) {
- print "'$value'";
- } else {
- print $value;
+ or $value =~ /^[\W]/
+ ) {
+ return "'$value'";
+ } else {
+ return $value;
}
+ } else {
+ return "_undef";
}
- else {
- print "undef";
- }
- }
- else { # some class instance
+ } else { # some class instance
return $value;
}
-} # end printitem
+} # end Item
### to print a list of something
-sub printArray {
+sub Array {
my (@values) = @_;
if (! scalar @values) {
- print "[]";
+ return "[]";
}
else { # the list is not empty
- my @res;
- print "[";
+ my $res = "[";
while (@values) {
my $value = shift @values;
- &printItem ($value);
- print ", " if (@values);
+ $res .= &Item ($value);
+ $res .= ", " if (@values);
}
- print "]" ;
+ return $res. "]" ;
}
-} # end printArray
+} # end Array
-sub printList {
- print "(";
+sub List {
+ my $res = "(";
while (@_) {
my $v = shift @_;
- printItem $v;
- if ($v =~ /^-\w+/) {
- print " => ";
- } elsif (@_) {
- print ", ";
+ $res .= Item ($v);
+ if (@_ > 0) {
+ ## still some elements
+ if ($v =~ /^-\d+$/) {
+ $res .= ", ";
+ } elsif ($v =~ /^-\w+$/) {
+ $res .= " => ";
+ } else {
+ $res .= ", ";
+ }
}
}
- print ")";
+ return $res. ")";
-} # end printList
+} # end List
1;