File Coverage

blib/lib/SVG/SVG2zinc/Backend/Tcl.pm
Criterion Covered Total %
statement 34 36 94.4
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 40 45 88.8


line stmt bran cond sub pod time code
1             package SVG::SVG2zinc::Backend::Tcl;
2              
3             # Backend Class for SVG2zinc
4             #
5             # Copyright 2003-2004
6             # Centre d'Études de la Navigation Aérienne
7             #
8             # Author: Christophe Mertz
9             #
10             # A module for code translation from perl to tcl generation
11             #
12             # $Id: Tcl.pm,v 1.2 2004/05/01 09:19:34 mertz Exp $
13             #############################################################################
14              
15              
16 1     1   515 use vars qw( $VERSION);
  1         2  
  1         107  
17             ($VERSION) = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
18              
19             @ISA = qw( Exporter );
20             @EXPORT = qw( perl2tcl );
21              
22 1     1   5 use strict;
  1         2  
  1         34  
23 1     1   5 use Carp;
  1         1  
  1         552  
24              
25              
26             sub perl2tcl {
27 4     4 0 1154 my (@lines) = @_;
28 4         6 my @res;
29 4         8 foreach my $l (@lines) {
30              
31 4         23 $l =~ s/->(\w*)\((.*)\)/\$w\.zinc $1 $2/g; # ->add(....) => $w.zinc add ...
32              
33 4         36 $l =~ s/\s*,\s*/ /g; # replacing commas by spaces
34 4         21 $l =~ s/\s*=>\s*/ /g; # replacing => by spaces
35              
36 4         48 $l =~ s/\s*\'([^\s;]+)\'\s*/ $1 /g ; # removing single-quotes around string without spaces
37 4         15 $l =~ s/\s*\"([^\s;]+)\"\s*/ $1 /g ; # removing double-quotes around string without spaces
38 4         6 $l =~ s/([\"\s])\#/$1\\\#/g ; # prefixing # by a slash
39              
40 4         7 $l =~ s/\[/\{/g; # replacing [ by }
41 4         9 $l =~ s/\]/\}/g; # replacing ] by }
42 4         8 $l =~ s/\{\s+/\{/g; # removing spaces after {
43 4         11 $l =~ s/\s+\}/\}/g; # removing spaces before }
44              
45 4         7 $l =~ s/-tags \{(\S+)\}/-tags $1/g; # -tags {toto} ==>> -tags toto
46 4         7 $l =~ s/\'/\"/g; # replacing all single quotes by double quotes
47              
48 4         8 $l = &hack($l);
49            
50 4         29 $l =~ s/\s+/ /g; # dangerous: removing multiple occurences of blanks
51              
52 4         11 $l =~ s/^\s+//; # removing blanks at the beginning
53 4         15 $l =~ s/\s+$//; # removing trailing blanks
54 4         13 $l =~ s/\s*;$//; # removing trailing ;
55 4         11 push @res, $l;
56             }
57 4         21 return (@res);
58             }
59              
60              
61             # this routine is used to do some special code transformation,
62             # due to soem discrepancies between tcl/tk and perl/tk
63             # the following code is more or less dependant from the generated
64             # code by SVG2zinc.pm
65             #
66             # We assume is code has already been tcl-ised
67             sub hack {
68 4     4 0 6 my ($l) = @_;
69              
70 4 50       13 if ($l =~ /^\$w\.zinc fontCreate/) {
71             # this works because I know how fontCreate is used in SVG2zinc
72 0         0 $l =~ s/\$w\.zinc fontCreate/font create/;
73 0         0 $l =~ s/-weight medium/-weight normal/;
74             }
75              
76 4         8 return $l;
77             }
78              
79             1;
80