From bae21c2bd9b182b6b6bc7810e5e9daf424ebab7c Mon Sep 17 00:00:00 2001 From: Pali Date: Sat, 18 Feb 2017 20:58:16 +0100 Subject: [PATCH] Email::MIME::Header: Add function set_class_for_header It will safely without overwriting modify hash: %Email::MIME::Header::header_to_class_map --- lib/Email/MIME.pm | 4 +++- lib/Email/MIME/Header.pm | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Email/MIME.pm b/lib/Email/MIME.pm index e206fe8..cf50e1d 100644 --- a/lib/Email/MIME.pm +++ b/lib/Email/MIME.pm @@ -908,7 +908,9 @@ This method returns an object representation of the header value. It instances new object via method C 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 for adding new +mapping. =method parts diff --git a/lib/Email/MIME/Header.pm b/lib/Email/MIME/Header.pm index 3aa09b2..4cfbec5 100644 --- a/lib/Email/MIME/Header.pm +++ b/lib/Email/MIME/Header.pm @@ -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;