X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/adc1751d8423b078e9f0fb7c5cd88ec8cc9f6935..4117f35a7b636c06817c7c6a94224e28adde8ee1:/Shiar_Sheet/Keyboard.pm diff --git a/Shiar_Sheet/Keyboard.pm b/Shiar_Sheet/Keyboard.pm index e8e33aa..30b73bf 100644 --- a/Shiar_Sheet/Keyboard.pm +++ b/Shiar_Sheet/Keyboard.pm @@ -1,11 +1,12 @@ package Shiar_Sheet::Keyboard; +use 5.010; use strict; use warnings; no warnings 'uninitialized'; # save some useless checks for more legible code use Carp; -our $VERSION = 'v2.03'; +our $VERSION = 'v2.04'; my @casedesc = (undef, qw/shift ctrl meta/, 'shift meta'); my @rowdesc = qw(numeric top home bottom); @@ -29,13 +30,11 @@ sub new { croak 'No key definitions specified' unless ref $self->{def} eq 'HASH'; $self->{map} ||= 'qwerty'; - my $parent = (caller)[0]; # calling module - my $sign = do { - no strict 'refs'; # temporarily allow variable references - \%{ $parent.'::sign' }; # return %sign from parent + $self->{sign} ||= do { + require Shiar_Sheet::KeySigns; + Shiar_Sheet::KeySigns->VERSION(1.04); + \%Shiar_Sheet::KeySigns::sign; }; - croak "%${parent}::sign not found" unless %$sign; - $self->{sign} = $sign; bless $self, $class; } @@ -66,6 +65,13 @@ sub escapehtml { return $_; } +sub escapedesc { + my $self = shift; + local $_ = shift; + s{ (< ([^>]*) >) }{ $self->{sign}->{$2} // $1 }xeg; + return $_; +} + sub keyunalias { my $self = shift; my ($key, $ancestry) = @_; @@ -94,7 +100,7 @@ sub print_key { } my ($flags, $desc, $mnem) = @{$flags}; if (my $txt = $self->{key}->{$mode.$key}) { - ($desc, $mnem) = split /\n/, $txt; + ($desc, $mnem) = split /\n/, $self->escapedesc($txt); } # $key = $keytrans{$key} if defined $keytrans{$key}; @@ -156,7 +162,7 @@ sub print_rows { ' class="%s"', join ' ', @caseclass ); printf('%s: %s', # XXX insert   here to fix msie<=6 - $self->{mode}->{$mode} || "mode $basemode", + $self->escapedesc($self->{mode}->{$mode} || "mode $basemode"), "$rowdesc[$row] row $casedesc[$case]" ) unless $row < 0; print "\n"; @@ -179,7 +185,7 @@ sub print_legend { print qq{\t\t
\n}; printf("\t\t".'
%s'."\n\t\t\t".'
%s'."\n", - $_, @{ $self->{flag}->{$_} || ["($_)", '...'] } + $_, map { $self->escapedesc($_) } @{ $self->{flag}->{$_} || ["($_)", '...'] } ) for @$flags; print "\t\t
"; }