7 use List::Util qw(first max);
9 my $file_name = (first { -f } qw(SL/ClientJS.pm ../SL/ClientJS.pm)) || die "ClientJS.pm not found";
12 foreach (read_file($file_name)) {
15 next unless (m/^my \%supported_methods/ .. m/^\);/);
17 push @actions, [ 'action', $1, $2 ] if m/^\s+([a-zA-Z]+)\s*=>\s*(\d+),$/;
18 push @actions, [ 'comment', $1 ] if m/^\s+#\s+(.+)/;
21 my $longest = max map { length($_->[1]) } grep { $_->[0] eq 'action' } @actions;
25 # else if (action[0] == 'hide') $(action[1]).hide();
26 foreach my $action (@actions) {
27 if ($action->[0] eq 'comment') {
28 print "\n" unless $first;
29 print " // ", $action->[1], "\n";
32 my $args = $action->[2] == 1 ? '' : join(', ', map { "action[$_]" } (2..$action->[2]));
34 printf(' %s if (action[0] == \'%s\')%s $(action[1]).%s(%s);' . "\n",
35 $first ? ' ' : 'else',
37 ' ' x ($longest - length($action->[1])),
44 printf "\n else\%sconsole.log('Unknown action: ' + action[0]);\n", ' ' x (4 + 2 + 6 + 3 + 4 + 2 + $longest + 1);