sub new { my ($class, @args) = @_; my ($encoding) = @args; my ($concrete_name, $concrete_path); ### Coerce the type to be legit: $encoding = lc($encoding || ''); ### Get the class: ($concrete_name = $DecoderFor{$encoding}) or return undef; ($concrete_path = $concrete_name.'.pm') =~ s{::}{/}g; ### Create the new object (if we can): my $self = { MD_Encoding => lc($encoding) }; require $concrete_path; bless $self, $concrete_name; $self->init(@args); } ### The stream decoders: %DecoderFor = ( ### Standard... '7bit' => 'MIME::Decoder::NBit', '8bit' => 'MIME::Decoder::NBit', 'base64' => 'MIME::Decoder::Base64', 'binary' => 'MIME::Decoder::Binary', 'none' => 'MIME::Decoder::Binary', 'quoted-printable' => 'MIME::Decoder::QuotedPrint', # snip ); sub init { $_[0]; }