countries: handle (multiple) aliases properly in flag mode
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 14 Jul 2015 00:40:35 +0000 (02:40 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 21 Sep 2015 22:20:08 +0000 (00:20 +0200)
countries.plp

index 61a4795..18b9860 100644 (file)
@@ -35,16 +35,24 @@ my $cc = do 'countries.inc.pl';
                        my ($name, $class, $short, $ref) = @$country;
                        $name .= " → $ref" if $ref;
                        $ref ||= $code;
-                       local $_ = $ref;
+                       my $cell;
                        if (exists $get{show}) {
-                               my $img = "data/flag/$ref.png";
-                               $_ = sprintf '<img src="/%s" alt="%s">', $img, $ref if -e $img;
+                               sub showflag {
+                                       my ($cc) = @_;
+                                       my $img = "data/flag/$cc.png";
+                                       return -e $img &&
+                                               sprintf '<img src="/%s" alt="%s">', $img, $cc;
+                               }
+
+                               $cell = showflag($code) // join(' ',
+                                       map { showflag($_) || $_ } split / /, $ref
+                               );
                        }
                        else {
-                               $_ = EscapeHTML($short || $name);
+                               $cell = EscapeHTML($short || $name);
                        }
                        printf "\n".'<td class="%s" title="%s">%s',
-                               $_ ? 'X '.$class : '', EscapeHTML("$code: $name"), $_;
+                               $cell ? 'X '.$class : '', EscapeHTML("$code: $name"), $cell;
                }
                print "\n";
        }