common module for ascii compatibility of unicode signs
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 5 Feb 2009 00:43:28 +0000 (00:43 +0000)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 22 Apr 2009 00:01:11 +0000 (00:01 +0000)
Shiar_Sheet/KeySigns.pm [new file with mode: 0644]
nethack.plp
vim.plp
vimperator.plp

diff --git a/Shiar_Sheet/KeySigns.pm b/Shiar_Sheet/KeySigns.pm
new file mode 100644 (file)
index 0000000..83289ab
--- /dev/null
@@ -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}" : '<wbr>',
+                       # 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: some<wbr>thing
+
+       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 <perl@shiar.org>
+
+=head1 LICENSE
+
+Copyright. All rights reserved.
+
index 8b48c853c07927eef9e6727c9f12358d081cddfb..dc8e616d826a36897e22b19c20851e53abbe818f 100644 (file)
@@ -5,21 +5,11 @@ use warnings;
 no  warnings 'qw';  # you know what you doing
 no  warnings 'uninitialized';  # save some useless checks for more legible code
 
-our $VERSION = '1.0';
+use Shiar_Sheet::KeySigns qw(%sign);
 
-our $ascii = 0;
-if (exists $get{ascii}) {
-       $ascii = $get{ascii} ne '0';  # manual override
-} elsif (defined $ENV{HTTP_ACCEPT_CHARSET}) {
-       $ascii = 1;
-       for (split q{,}, $ENV{HTTP_ACCEPT_CHARSET}) {
-               $ascii = 0, last if $_ eq '*' or m{utf-?8}i;
-       }
-}
+our $VERSION = '1.0';
 
-my $charset = $ascii ? 'us-ascii' : 'utf-8';
-my $ctype = "text/html; charset=$charset";
-$header{content_type} = $ctype;
+$header{content_type} = "text/html; charset=$sign{charset}";
 
 :><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
@@ -27,7 +17,7 @@ $header{content_type} = $ctype;
 
 <head>
 <title>nethack cheat sheet</title>
-<meta http-equiv="content-type" content="<:= $ctype :>">
+<meta http-equiv="content-type" content="<:= $header{content_type} :>">
 <link rel="stylesheet" type="text/css" media="all" href="base.css">
 <!--[if lte IE 6]><style> .help dl.legend dt {margin:0 0 1px} </style><![endif]-->
 <!--[if lte IE 7]><style> .help dl.legend dd {float:none} </style><![endif]--><:
@@ -60,23 +50,6 @@ $header{content_type} = $ctype;
 </li>
 
 <:
-our %sign = (
-       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 ? '*'     : '•',
-       _      => exists $get{ascii} && !$ascii ? "\x{200b}" : '<wbr>',
-               # use the correct ZWNJ only when unicode is forced on
-               # default to use unofficial html for best support
-);
-
 use Shiar_Sheet::Keyboard;
 my $keys = Shiar_Sheet::Keyboard->new({do 'nethack.inc.pl'});
 $keys->map($get{map}) or undef $get{map};
@@ -118,8 +91,8 @@ $keys->print_rows($get{static});
                <li>keyboard <strong>map</strong> is
                        <:= $get{map} ? 'set to ' : '' :><em><:= $keys->{map} :></em>
                <li><strong>ascii</strong> mode is
-                       <:= exists $get{ascii} && 'forced ' :><em><:=
-                               $ascii ? 'on' : 'off' :></em>
+                       <:= defined $sign{-ascii} && 'forced ' :><em><:=
+                               $sign{-ascii} ? 'on' : 'off' :></em>
                <li><strong>keys</strong> are
                        <em><:= $showkeys ? 'always shown' : 'hidden if unassigned' :></em><:=
                                !exists $get{keys} && ' by default' :>
diff --git a/vim.plp b/vim.plp
index e2890bf9d971c847156178e319da6a408db0096f..b8a1f5c5083b69d08e9007b9d43d052443a92f35 100644 (file)
--- a/vim.plp
+++ b/vim.plp
@@ -5,21 +5,11 @@ use warnings;
 no  warnings 'qw';  # you know what you doing
 no  warnings 'uninitialized';  # save some useless checks for more legible code
 
-our $VERSION = '1.2';
+use Shiar_Sheet::KeySigns qw(%sign);  # dependant on $get{ascii}
 
-our $ascii = 0;
-if (exists $get{ascii}) {
-       $ascii = $get{ascii} ne '0';  # manual override
-} elsif (defined $ENV{HTTP_ACCEPT_CHARSET}) {
-       $ascii = 1;
-       for (split q{,}, $ENV{HTTP_ACCEPT_CHARSET}) {
-               $ascii = 0, last if $_ eq '*' or m{utf-?8}i;
-       }
-}
+our $VERSION = '1.2';
 
-my $charset = $ascii ? 'us-ascii' : 'utf-8';
-my $ctype = "text/html; charset=$charset";
-$header{content_type} = $ctype;
+$header{content_type} = "text/html; charset=$sign{charset}";
 
 :><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
@@ -27,7 +17,7 @@ $header{content_type} = $ctype;
 
 <head>
 <title>vi cheat sheet</title>
-<meta http-equiv="content-type" content="<:= $ctype :>">
+<meta http-equiv="content-type" content="<:= $header{content_type} :>">
 <link rel="stylesheet" type="text/css" media="all" href="base.css">
 <!--[if lte IE 6]><style> .help dl.legend dt {margin:0 0 1px} </style><![endif]-->
 <!--[if lte IE 7]><style> .help dl.legend dd {float:none} </style><![endif]--><:
@@ -60,20 +50,6 @@ $header{content_type} = $ctype;
 </li>
 
 <:
-our %sign = (
-       arg    => $ascii ? '.' : '·',  # described as 'dot'
-       motion => $ascii ? '|' : '↕',
-       alias  => $ascii ? 'see: ' : '»',
-       up     => $ascii ? 'up'    : '▲',
-       right  => $ascii ? 'right' : '▶',
-       down   => $ascii ? 'down'  : '▼',
-       left   => $ascii ? 'left'  : '◀',
-       sep    => $ascii ? '*'     : '•',
-       _      => exists $get{ascii} && !$ascii ? "\x{200b}" : '<wbr>',
-               # use the correct ZWNJ only when unicode is forced on
-               # default to use unofficial html for best support
-);
-
 use Shiar_Sheet::Keyboard;
 my $keys = Shiar_Sheet::Keyboard->new({do 'vim.inc.pl'});
 $keys->map($get{map}) or undef $get{map};
@@ -121,8 +97,8 @@ $keys->print_rows($get{static});
                <li>keyboard <strong>map</strong> is
                        <:= $get{map} ? 'set to ' : '' :><em><:= $keys->{map} :></em>
                <li><strong>ascii</strong> mode is
-                       <:= exists $get{ascii} && 'forced ' :><em><:=
-                               $ascii ? 'on' : 'off' :></em>
+                       <:= defined $sign{-ascii} && 'forced ' :><em><:=
+                               $sign{-ascii} ? 'on' : 'off' :></em>
                <li><strong>keys</strong> are
                        <em><:= $showkeys ? 'always shown' : 'hidden if unassigned' :></em><:=
                                !exists $get{keys} && ' by default' :>
index 660d8197576bb0fba1cad69c3be3214ba9797c8e..cdde680ad89c03ab1023af3af892578beb2298fc 100644 (file)
@@ -5,21 +5,11 @@ use warnings;
 no  warnings 'qw';  # you know what you doing
 no  warnings 'uninitialized';  # save some useless checks for more legible code
 
-our $VERSION = '1.0';
+use Shiar_Sheet::KeySigns qw(%sign);
 
-our $ascii = 0;
-if (exists $get{ascii}) {
-       $ascii = $get{ascii} ne '0';  # manual override
-} elsif (defined $ENV{HTTP_ACCEPT_CHARSET}) {
-       $ascii = 1;
-       for (split q{,}, $ENV{HTTP_ACCEPT_CHARSET}) {
-               $ascii = 0, last if $_ eq '*' or m{utf-?8}i;
-       }
-}
+our $VERSION = '1.0';
 
-my $charset = $ascii ? 'us-ascii' : 'utf-8';
-my $ctype = "text/html; charset=$charset";
-$header{content_type} = $ctype;
+$header{content_type} = "text/html; charset=$sign{charset}";
 
 :><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
@@ -27,7 +17,7 @@ $header{content_type} = $ctype;
 
 <head>
 <title>vimperator cheat sheet</title>
-<meta http-equiv="content-type" content="<:= $ctype :>">
+<meta http-equiv="content-type" content="<:= $header{content_type} :>">
 <link rel="stylesheet" type="text/css" media="all" href="base.css">
 <!--[if lte IE 6]><style> .help dl.legend dt {margin:0 0 1px} </style><![endif]-->
 <!--[if lte IE 7]><style> .help dl.legend dd {float:none} </style><![endif]--><:
@@ -60,20 +50,6 @@ $header{content_type} = $ctype;
 </li>
 
 <:
-our %sign = (
-       arg    => $ascii ? '.' : '·',  # described as 'dot'
-       args   => $ascii ? ':' : '⁚',  # described as 'two dots'
-       alias  => $ascii ? 'see: ' : '»',
-       up     => $ascii ? 'up'    : '▲',
-       right  => $ascii ? 'right' : '▶',
-       down   => $ascii ? 'down'  : '▼',
-       left   => $ascii ? 'left'  : '◀',
-       sep    => $ascii ? '*'     : '•',
-       _      => exists $get{ascii} && !$ascii ? "\x{200b}" : '<wbr>',
-               # use the correct ZWNJ only when unicode is forced on
-               # default to use unofficial html for best support
-);
-
 use Shiar_Sheet::Keyboard;
 my $keys = Shiar_Sheet::Keyboard->new({do 'vimperator.inc.pl'});
 $keys->map($get{map}) or undef $get{map};
@@ -119,8 +95,8 @@ $keys->print_rows($get{static});
                <li>keyboard <strong>map</strong> is
                        <:= $get{map} ? 'set to ' : '' :><em><:= $keys->{map} :></em>
                <li><strong>ascii</strong> mode is
-                       <:= exists $get{ascii} && 'forced ' :><em><:=
-                               $ascii ? 'on' : 'off' :></em>
+                       <:= defined $sign{-ascii} && 'forced ' :><em><:=
+                               $sign{-ascii} ? 'on' : 'off' :></em>
                <li><strong>keys</strong> are
                        <em><:= $showkeys ? 'always shown' : 'hidden if unassigned' :></em><:=
                                !exists $get{keys} && ' by default' :>