Skip Menu |

This queue is for tickets about the Encode CPAN distribution.

Report information
The Basics
Id: 63286
Status: resolved
Priority: 0/
Queue: Encode

People
Owner: Nobody in particular
Requestors: GAAS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Various Encode::Alias improvements
I have a set of patches (relative to Encode-2.40) to fix up the test suite for Encode::Alias, fix how alias callbacks are handled and documentation tweaks. This set of patches is also available as <https://github.com/dankogai/p5-encode/pull/1>.
Subject: 0004-Improved-synopsis-for-Encode-Alias.patch
From 75618a4b44dedc3a2435d5a01ff74592cab6d330 Mon Sep 17 00:00:00 2001 From: Gisle Aas <gisle@aas.no> Date: Sat, 20 Nov 2010 00:41:13 +0100 Subject: [PATCH 4/6] Improved synopsis for Encode::Alias --- lib/Encode/Alias.pm | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Encode/Alias.pm b/lib/Encode/Alias.pm index d8b1b15..a5e90df 100644 --- a/lib/Encode/Alias.pm +++ b/lib/Encode/Alias.pm @@ -286,7 +286,9 @@ Encode::Alias - alias definitions to encodings use Encode; use Encode::Alias; - define_alias( newName => ENCODING); + define_alias( "newName" => ENCODING); + define_alias( qr/.../ => ENCODING); + define_alias( sub { return ENCODING if ...; } ); =head1 DESCRIPTION @@ -294,7 +296,8 @@ Allows newName to be used as an alias for ENCODING. ENCODING may be either the name of an encoding or an encoding object (as described in L<Encode>). -Currently I<newName> can be specified in the following ways: +Currently the first argument to define_alias() can be specified in the +following ways: =over 4 @@ -321,7 +324,7 @@ experienced. Use this feature with caution. The same effect as the example above in a different way. The coderef takes the alias name as an argument and returns a canonical name on -success or undef if not. Note the second argument is not required. +success or undef if not. Note the second argument is ignored if provided. Use this with even more caution than the regex version. =back -- 1.6.6.rc1.31.g1a56b
Subject: 0002-Remove-the-correct-alias-cache-entries-when-a-code-r.patch
From b4b4a432b8f5132e78c60c9ca94075a653aee6d8 Mon Sep 17 00:00:00 2001 From: Gisle Aas <gisle.aas@it.uib.no> Date: Sat, 13 Nov 2010 22:59:27 +0100 Subject: [PATCH 2/6] Remove the correct alias cache entries when a code reference is provided --- lib/Encode/Alias.pm | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Encode/Alias.pm b/lib/Encode/Alias.pm index f142403..d8b1b15 100644 --- a/lib/Encode/Alias.pm +++ b/lib/Encode/Alias.pm @@ -90,9 +90,9 @@ sub define_alias { DEBUG and warn "delete \$Alias\{$k\}"; delete $Alias{$k}; } - elsif ( ref($alias) eq 'CODE' ) { + elsif ( ref($alias) eq 'CODE' && $alias->($k) ) { DEBUG and warn "delete \$Alias\{$k\}"; - delete $Alias{ $alias->($name) }; + delete $Alias{$k}; } } } -- 1.6.6.rc1.31.g1a56b
Subject: 0001-Fix-up-non-working-overide-tests.patch
From 716292c18d3e6d45f05c967e7f3b60009f10e5cd Mon Sep 17 00:00:00 2001 From: Gisle Aas <gisle.aas@it.uib.no> Date: Sun, 14 Nov 2010 19:15:17 +0100 Subject: [PATCH 1/6] Fix up non-working overide tests With regexp defined one need to use *double* quotes. --- t/Aliases.t | 21 +++++++++++---------- 1 files changed, 11 insertions(+), 10 deletions(-) diff --git a/t/Aliases.t b/t/Aliases.t index fd088d5..dc159b1 100644 --- a/t/Aliases.t +++ b/t/Aliases.t @@ -16,6 +16,7 @@ use strict; use Encode; use Encode::Alias; my %a2c; +my @override_tests; my $ON_EBCDIC; sub init_a2c{ @@ -108,6 +109,7 @@ BEGIN{ @ARGV and $ON_EBCDIC = $ARGV[0] eq 'EBCDIC'; $Encode::ON_EBCDIC = $ON_EBCDIC; init_a2c(); + @override_tests = qw(myascii:cp1252 mygreek:cp1253); } if ($ON_EBCDIC){ @@ -120,7 +122,7 @@ if ($ON_EBCDIC){ }; } -use Test::More tests => (scalar keys %a2c) * 4; +use Test::More tests => (scalar keys %a2c) * 3 + @override_tests; print "# alias test; \$ON_EBCDIC == $ON_EBCDIC\n"; @@ -134,20 +136,19 @@ foreach my $a (keys %a2c){ # now we override some of the aliases and see if it works fine define_alias( - qr/ascii/i => 'WinLatin1', - qr/cyrillic/i => 'WinCyrillic', - qr/arabic/i => 'WinArabic', - qr/greek/i => 'WinGreek', - qr/hebrew/i => 'WinHebrew' + qr/ascii/i => '"WinLatin1"', + qr/cyrillic/i => '"WinCyrillic"', + qr/arabic/i => '"WinArabic"', + qr/greek/i => '"WinGreek"', + qr/hebrew/i => '"WinHebrew"' ); print "# alias test with alias overrides\n"; -foreach my $a (keys %a2c){ - print "# $a => $a2c{$a}\n"; +for my $test (@override_tests) { + my($a, $c) = split /:/, $test; my $e = Encode::find_encoding($a); - is((defined($e) and $e->name), $a2c{$a}, "Override $a") - or warn "alias was $a"; + is((defined($e) and $e->name), $c, $a); } print "# alias undef test\n"; -- 1.6.6.rc1.31.g1a56b
Subject: 0005-Aliases-can-t-override-canonical-names.patch
From eab9263bbf585ad9c03527c18b3f492e692276a7 Mon Sep 17 00:00:00 2001 From: Gisle Aas <gisle@aas.no> Date: Sat, 20 Nov 2010 00:46:53 +0100 Subject: [PATCH 5/6] Aliases can't override canonical names --- lib/Encode/Alias.pm | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/lib/Encode/Alias.pm b/lib/Encode/Alias.pm index a5e90df..97b61fa 100644 --- a/lib/Encode/Alias.pm +++ b/lib/Encode/Alias.pm @@ -372,6 +372,10 @@ to do so. And gets the factory settings back. +Note that define_alias() will not be able to override the canonical name +of encodings. Encodings are first looked up by canonical name before +potential aliases are tried. + =head1 SEE ALSO L<Encode>, L<Encode::Supported> -- 1.6.6.rc1.31.g1a56b
Subject: 0003-Test-alias-callback.patch
From 124839555ac98e035d254b06f40ef9fbb8abe100 Mon Sep 17 00:00:00 2001 From: Gisle Aas <gisle@aas.no> Date: Sat, 20 Nov 2010 00:19:22 +0100 Subject: [PATCH 3/6] Test alias callback --- t/Aliases.t | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/t/Aliases.t b/t/Aliases.t index dc159b1..d7a72d2 100644 --- a/t/Aliases.t +++ b/t/Aliases.t @@ -109,7 +109,14 @@ BEGIN{ @ARGV and $ON_EBCDIC = $ARGV[0] eq 'EBCDIC'; $Encode::ON_EBCDIC = $ON_EBCDIC; init_a2c(); - @override_tests = qw(myascii:cp1252 mygreek:cp1253); + @override_tests = qw( + myascii:cp1252 + mygreek:cp1253 + myhebrew:iso-8859-2 + myarabic:cp1256 + ueightsomething:utf-8-strict + unknown: + ); } if ($ON_EBCDIC){ @@ -143,6 +150,16 @@ define_alias( qr/hebrew/i => '"WinHebrew"' ); +Encode::find_encoding("myhebrew"); # polute alias cache + +define_alias( sub { + my $enc = shift; + return "iso-8859-2" if $enc =~ /hebrew/i; + return "does-not-exist" if $enc =~ /arabic/i; # should then use other override alias + return "utf-8" if $enc =~ /eight/i; + return; +}); + print "# alias test with alias overrides\n"; for my $test (@override_tests) { -- 1.6.6.rc1.31.g1a56b
Gaas, Thanks. applied in my repo. Dan the Encode Maintainer On Tue Nov 23 14:26:41 2010, GAAS wrote: Show quoted text
> I have a set of patches (relative to Encode-2.40) to fix up the test > suite for Encode::Alias, fix how alias callbacks are handled and > documentation tweaks. This set of > patches is also available as <https://github.com/dankogai/p5- > encode/pull/1>.