Skip to content

Commit

Permalink
Email::MIME::Header: Add function set_class_for_header
Browse files Browse the repository at this point in the history
It will safely without overwriting modify hash: %Email::MIME::Header::header_to_class_map
  • Loading branch information
pali committed Feb 18, 2017
1 parent 485ab2b commit bae21c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Email/MIME.pm
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,9 @@ This method returns an object representation of the header value. It instances
new object via method C<from_mime_string> of specified class. Input argument
for that class method is list of the raw MIME-encoded values. If class argument
is not specified then class name is taken from the hash
C<%Email::MIME::Header::header_to_class_map> via key field.
C<%Email::MIME::Header::header_to_class_map> via key field. Use function
C<Email::MIME::Header::set_class_for_header($class, $field)> for adding new
mapping.
=method parts
Expand Down
8 changes: 8 additions & 0 deletions lib/Email/MIME/Header.pm
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,12 @@ sub _maybe_decode {
return;
}

sub set_class_for_header {
my ($class, $header) = @_;
$header = lc $header;
Carp::croak("Class for header '$header' is already set") if defined $header_to_class_map{$header};
$header_to_class_map{$header} = $class;
return;
}

1;

0 comments on commit bae21c2

Please sign in to comment.