X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/4d0e83fa3326d3c63eb024858f9346daf50e917a..7ca5c909537ead4ccef2a451538c345544834b65:/Shiar_Sheet/KeySigns.pm diff --git a/Shiar_Sheet/KeySigns.pm b/Shiar_Sheet/KeySigns.pm new file mode 100644 index 0000000..83289ab --- /dev/null +++ b/Shiar_Sheet/KeySigns.pm @@ -0,0 +1,72 @@ +package Shiar_Sheet::KeySigns; + +use utf8; +use strict; +use warnings; + +our $VERSION = '1.00'; + +sub import { + my $class = shift; + + my $ascii = undef; + if (exists $PLP::Script::get{ascii}) { + # manual override + $ascii = !defined $PLP::Script::get{ascii} || $PLP::Script::get{ascii} !~ /^0*$/; + } + elsif (defined $ENV{HTTP_ACCEPT_CHARSET}) { + $ascii = 1; + for (split q{,}, $ENV{HTTP_ACCEPT_CHARSET}) { + $ascii = undef, last if $_ eq '*' or m{utf-?8}i; + } + } + + my %sign = ( + -ascii => $ascii, + charset=> $ascii ? 'us-ascii' : 'utf-8', + arg => $ascii ? '.' : '·', # described as 'dot' + args => $ascii ? ':' : '⁚', + argi => $ascii ? "'" : '′', + argm => $ascii ? '|' : '↕', + motion => $ascii ? '|' : '↕', + alias => $ascii ? 'see: ' : '»', + up => $ascii ? 'up' : '▲', + right => $ascii ? 'right' : '▶', + down => $ascii ? 'down' : '▼', + left => $ascii ? 'left' : '◀', + sep => $ascii ? '*' : '•', + _ => defined $ascii && !$ascii ? "\x{200b}" : '', + # use the correct ZWNJ only when unicode is forced on + # default to use unofficial html for best support + ); + + my ($parent) = caller; + eval '*'.$parent.'::sign = \%sign'; +} + +1; + +__END__ + +=head1 NAME + +Shiar_Sheet::KeySigns - Common Unicode characters in user-preferred charset + +=head1 SYNOPSIS + + use Shiar_Sheet::KeySigns; + print "$sign{alias} some$sign{_}thing"; # see: something + + package PLP::Script; + our %get = (ascii => 0); # user input + Shiar_Sheet::KeySigns->import; + print "$sign{alias} some$sign{_}thing"; # »some( )thing + +=head1 AUTHOR + +Mischa POSLAWSKY + +=head1 LICENSE + +Copyright. All rights reserved. +