Change 18088 by merijn@merijn-l1 on 2002/11/04 15:37:06
Charnames take 4
Mon, 04 Nov 2002; H.Merijn Brand <[EMAIL PROTECTED]>
Affected files ...
.... //depot/perl/lib/charnames.pm#37 edit
.... //depot/perl/lib/charnames.t#22 edit
Differences ...
==== //depot/perl/lib/charnames.pm#37 (text) ====
Index: perl/lib/charnames.pm
--- perl/lib/charnames.pm#36~18053~ Thu Oct 24 01:20:09 2002
+++ perl/lib/charnames.pm Mon Nov 4 07:37:06 2002
@@ -2,6 +2,7 @@
use strict;
use warnings;
use Carp;
+use File::Spec;
our $VERSION = '1.02';
use bytes (); # for $bytes::hint_bits
@@ -52,9 +53,21 @@
sub alias_file ($)
{
- my $arg = shift;
- my $file = -f $arg ? $arg : "unicore/${arg}_alias.pl";
+ my ($arg, $file) = @_;
+ if (-f $arg && File::Spec->file_name_is_absolute ($arg)) {
+ $file = $arg;
+ }
+ elsif ($arg =~ m/^\w+$/) {
+ $file = "unicore/${arg}_alias.pl";
+ }
+ else {
+ croak "Charnames alias files can only have identifier characters";
+ }
if (my @alias = do $file) {
+ @alias == 1 && !defined $alias[0] and
+ croak "$file cannot be used as alias file for charnames";
+ @alias % 2 and
+ croak "$file did not return a (valid) list of alias pairs";
alias (@alias);
return (1);
}
@@ -178,18 +191,28 @@
##
my ($promote, %h, @args) = (0);
while (@_ and $_ = shift) {
- if ($_ eq ":alias" && @_) {
+ if ($_ eq ":alias") {
+ @_ or
+ croak ":alias needs an argument in charnames";
my $alias = shift;
if (ref $alias) {
ref $alias eq "HASH" or
- die "Only HASH reference supported as argument to :alias";
+ croak "Only HASH reference supported as argument to :alias";
alias ($alias);
next;
}
- if ($alias =~ m{:(\w+)$} and $1 ne "full" && $1 ne "short") {
- alias_file ($1) and $promote = 1, next;
+ if ($alias =~ m{:(\w+)$}) {
+ $1 eq "full" || $1 eq "short" and
+ croak ":alias cannot use existing pragma :$1 (reversed order?)";
+ alias_file ($1) and $promote = 1;
+ next;
}
- alias_file ($alias) and next;
+ alias_file ($alias);
+ next;
+ }
+ if (m/^:/ and ! ($_ eq ":full" || $_ eq ":short")) {
+ warn "unsupported special '$_' in charnames";
+ next;
}
push @args, $_;
}
==== //depot/perl/lib/charnames.t#22 (text) ====
Index: perl/lib/charnames.t
--- perl/lib/charnames.t#21~18053~ Thu Oct 24 01:20:09 2002
+++ perl/lib/charnames.t Mon Nov 4 07:37:06 2002
@@ -12,7 +12,7 @@
$| = 1;
-print "1..69\n";
+print "1..73\n";
use charnames ':full';
@@ -95,7 +95,7 @@
{
use charnames qw(:full);
use utf8;
-
+
my $x = "\x{221b}";
my $named = "\N{CUBE ROOT}";
@@ -119,7 +119,7 @@
}
{
- # 20001114.001
+ # 20001114.001
no utf8; # naked Latin-1
@@ -328,17 +328,29 @@
}
__END__
+# unsupported pragma
+use charnames ":scoobydoo";
+"Here: \N{e_ACUTE}!\n";
+EXPECT
+unsupported special ':scoobydoo' in charnames at
+########
# wrong type of alias (missing colon)
use charnames "alias";
"Here: \N{e_ACUTE}!\n";
EXPECT
-Unknown charname 'e_ACUTE' at
+Unknown charname 'e_ACUTE' at
########
# alias without an argument
use charnames ":alias";
"Here: \N{e_ACUTE}!\n";
EXPECT
-Unknown charname 'e_ACUTE' at
+:alias needs an argument in charnames at
+########
+# reversed sequence
+use charnames ":alias" => ":full";
+"Here: \N{e_ACUTE}!\n";
+EXPECT
+:alias cannot use existing pragma :full \(reversed order\?\) at
########
# alias with hashref but no :full
use charnames ":alias" => { e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE" };
@@ -374,7 +386,7 @@
use charnames ":short", ":alias" => "e_ACUTE";
"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
EXPECT
-Odd number of elements in anonymous hash at
+unicore/e_ACUTE_alias.pl cannot be used as alias file for charnames at
########
# alias with arrayref
use charnames ":short", ":alias" => [ e_ACUTE => "LATIN:e WITH ACUTE" ];
@@ -437,7 +449,19 @@
use charnames ":full", ":alias" => "xyzzy";
"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
EXPECT
-Odd number of elements in anonymous hash at
+unicore/xyzzy_alias.pl cannot be used as alias file for charnames at
+########
+# alias with bad file name
+use charnames ":full", ":alias" => "xy 7-";
+"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
+EXPECT
+Charnames alias files can only have identifier characters at
+########
+# alias with non_absolute (existing) file name (which it should /not/ use)
+use charnames ":full", ":alias" => "perl";
+"Here: \N{e_ACUTE}\N{a_ACUTE}!\n";
+EXPECT
+unicore/perl_alias.pl cannot be used as alias file for charnames at
########
# alias with bad file
use charnames ":full", ":alias" => "xyzzy";
@@ -446,7 +470,7 @@
#!perl
0;
EXPECT
-Odd number of elements in anonymous hash at
+unicore/xyzzy_alias.pl did not return a \(valid\) list of alias pairs at
########
# alias with file with empty list
use charnames ":full", ":alias" => "xyzzy";
End of Patch.