Subject: | Color names that don't appear in keys %tied_var |
It might be a good idea to have color names that are recognized but don't
appear in the list of available color names. One example is "fuscia". It is not
a valid color name but it should still be recognized.
This is important when you want to use the maps to translate colors back to
their names. Currently, there's no indication whether you should translate
#FF00FF to "fuscia" or "fuchsia", so you can't simple use
Graphics::ColorNames::HTML in order not to have to maintain your own list.
Well, there's a patch attached, which implements the feature.
Nur in Graphics-ColorNames.new: blib.
diff -ur Graphics-ColorNames-2.0_01/lib/Graphics/ColorNames/HTML.pm Graphics-ColorNames.new/lib/Graphics/ColorNames/HTML.pm
--- Graphics-ColorNames-2.0_01/lib/Graphics/ColorNames/HTML.pm 2004-07-22 21:52:45.000000000 +0200
+++ Graphics-ColorNames.new/lib/Graphics/ColorNames/HTML.pm 2005-04-06 15:33:39.052949274 +0200
@@ -53,8 +53,7 @@
'blue' => 0x0000ff,
'aqua' => 0x00ffff,
'lime' => 0x00ff00,
- 'fuchsia' => 0xff00ff, # "fuscia" is incorrect but common
- 'fuscia' => 0xff00ff, # mis-spelling...
+ 'fuchsia' => 0xff00ff,
'red' => 0xff0000,
'yellow' => 0xffff00,
'white' => 0xffffff,
@@ -69,6 +68,14 @@
};
}
+sub NamesRgbTableExtra() {
+ use integer;
+ return {
+ 'fuscia' => 0xff00ff, # "fuscia" is incorrect but common
+ # mis-spelling...
+ };
+}
+
1;
__END__
diff -ur Graphics-ColorNames-2.0_01/lib/Graphics/ColorNames.pm Graphics-ColorNames.new/lib/Graphics/ColorNames.pm
--- Graphics-ColorNames-2.0_01/lib/Graphics/ColorNames.pm 2005-04-04 15:15:29.000000000 +0200
+++ Graphics-ColorNames.new/lib/Graphics/ColorNames.pm 2005-04-06 15:46:39.641545953 +0200
@@ -121,6 +121,12 @@
{
no strict 'refs';
$self->load_scheme($module->NamesRgbTable);
+
+ if(my $m = UNIVERSAL::can($module, 'NamesRgbTableExtra'))
+ {
+ local $self->{NAMES} = ($self->{NAMES_EXTRA} ||= {});
+ $self->load_scheme($m->());
+ }
}
}
@@ -190,6 +196,9 @@
} else {
my $value = $self->{NAMES}->{$key};
unless (defined $value) {
+ $value = $self->{NAMES_EXTRA}->{$key};
+ }
+ unless (defined $value) {
my @schemes = @{ $self->{SCHEMES} };
while ((!defined $value) && (my $scheme = shift @schemes)) {
if ((ref $scheme) eq 'CODE') {
Nur in Graphics-ColorNames.new: Makefile.
Nur in Graphics-ColorNames.new: pm_to_blib.
diff -ur Graphics-ColorNames-2.0_01/t/03-HTML.t Graphics-ColorNames.new/t/03-HTML.t
--- Graphics-ColorNames-2.0_01/t/03-HTML.t 2005-03-30 01:44:44.000000000 +0200
+++ Graphics-ColorNames.new/t/03-HTML.t 2005-04-06 15:49:25.329616388 +0200
@@ -8,7 +8,7 @@
tie my %colors, 'Graphics::ColorNames', 'HTML';
ok(tied %colors);
-ok(keys %colors == 17);
+ok(keys %colors == 16);
my $count = 0;
foreach my $name (keys %colors)