keys: declare common signs in module global
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 4 Feb 2015 01:09:05 +0000 (02:09 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 5 Feb 2015 21:46:21 +0000 (22:46 +0100)
Allow the pertinent Shiar_Sheet::KeySigns variable to be used without
importing.

Shiar_Sheet/KeySigns.pm
Shiar_Sheet/Keyboard.pm

index 069b8fa732220bd9c459c1afff85fa6a28cf26f5..c65385ce5415d71aefdb615a39c0d51e8f0dcb80 100644 (file)
@@ -4,12 +4,9 @@ use utf8;
 use strict;
 use warnings;
 
-our $VERSION = 'v1.02';
+our $VERSION = '1.03';
 
-sub import {
-       my $class = shift;
-
-       my %sign = (
+our %sign = (
                arg    => '·',  # described as 'dot'
                args   => '⁚',
                argi   => '′',
@@ -22,8 +19,10 @@ sub import {
                left   => '◀',
                sep    => '•',
                _      => '<wbr>' || "\x{200b}",  # unofficial html, correct ZWNJ character might appear as placeholder
-       );
+);
 
+sub import {
+       # exports %sign
        my ($parent) = caller;
        eval '*'.$parent.'::sign = \%sign';
 }
index e8e33aa0283f22c88e4c094a3ac3631443210efb..aecd0bc9773a04dd4a3eb3a2b57127f778d7dc04 100644 (file)
@@ -29,13 +29,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.03);
+               \%Shiar_Sheet::KeySigns::sign;
        };
-       croak "%${parent}::sign not found" unless %$sign;
-       $self->{sign} = $sign;
 
        bless $self, $class;
 }