Skip to content

Commit

Permalink
Add Vend::CharSet::mime_name for installations which lack proper Enco…
Browse files Browse the repository at this point in the history
…de.pm support

Not all versions of Encode in IC-supported perl versions support the
mime_name method.  This patch adds checking for the existance of the
method, and provides a simple replacement in the case that it lacks
it.

The main goal here is to support earlier versions of Encode.pm, while
still allowing us to normalize and use the utf8 charset.

Additional special-cases can be added to Vend::CharSet::mime_name as needed.
  • Loading branch information
David Christensen committed Nov 24, 2009
1 parent a53a955 commit 10929c6
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/Vend/CharSet.pm
Expand Up @@ -73,11 +73,26 @@ sub to_internal {
return $octets;
}

# returns a true value (the normalized name of the encoding) if the
# specified encoding is recognized by Encode.pm, otherwise return
# nothing.
sub validate_encoding {
my $encoding = shift;
my $enc = find_encoding($encoding);

return $enc && $enc->mime_name;
return unless $enc;
return $enc->can('mime_name') ? $enc->mime_name : mime_name($enc->name);
}

# fallback routine to provide a pretty-style mime_name in versions of
# Encode which predate the actual method. The main use would be to
# normalize "utf8-strict" to "utf8", but there are other cases where
# this can/will come in handy.
sub mime_name {
my $encoding_name = shift;

$encoding_name =~ s/-strict//i;
return lc $encoding_name;
}

sub default_charset {
Expand Down

0 comments on commit 10929c6

Please sign in to comment.