Entity.pm =1849= ### Get the encoding, defaulting to "binary" if unsupported: =1850= my $encoding = ($self->head->mime_encoding || 'binary'); =1851= my $decoder = best MIME::Decoder $encoding; =1852= $decoder->head($self->head); ### associate with head, if any #### Decoder.pm sub best { my ($class, $enc, @args) = @_; my $self = $class->new($enc, @args); if (!$self) { usage "unsupported encoding '$enc': using 'binary'"; $self = $class->new('binary') || croak "ack! no binary decoder!"; } $self; } #### 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]; }