From f91fd6d772ee8ea35f833802c9f8cc1db75ca950 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 4 Feb 2015 02:09:05 +0100 Subject: [PATCH 1/1] keys: declare common signs in module global Allow the pertinent Shiar_Sheet::KeySigns variable to be used without importing. --- Shiar_Sheet/KeySigns.pm | 11 +++++------ Shiar_Sheet/Keyboard.pm | 10 ++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Shiar_Sheet/KeySigns.pm b/Shiar_Sheet/KeySigns.pm index 069b8fa..c65385c 100644 --- a/Shiar_Sheet/KeySigns.pm +++ b/Shiar_Sheet/KeySigns.pm @@ -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 => '•', _ => '' || "\x{200b}", # unofficial html, correct ZWNJ character might appear as placeholder - ); +); +sub import { + # exports %sign my ($parent) = caller; eval '*'.$parent.'::sign = \%sign'; } diff --git a/Shiar_Sheet/Keyboard.pm b/Shiar_Sheet/Keyboard.pm index e8e33aa..aecd0bc 100644 --- a/Shiar_Sheet/Keyboard.pm +++ b/Shiar_Sheet/Keyboard.pm @@ -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; } -- 2.30.0