Email::MIME::Kit::Role::ManifestDesugarer - helper for desugaring manifests


Email-MIME-Kit documentation Contained in the Email-MIME-Kit distribution.

Index


Code Index:

NAME

Top

Email::MIME::Kit::Role::ManifestDesugarer - helper for desugaring manifests

VERSION

Top

version 2.102010

IMPLEMENTING

Top

This role also performs Email::MIME::Kit::Role::Component.

This is a role more likely to be consumed than implemented. It wraps around the read_manifest method in the consuming class, and "desugars" the contents of the loaded manifest before returning it.

At present, desugaring is what allows the type attribute in attachments and alternatives to be given instead of a content_type entry in the attributes entry. In other words, desugaring turns:

  {
    header => [ ... ],
    type   => 'text/plain',
  }

Into:

  {
    header => [ ... ],
    attributes => { content_type => 'text/plain' },
  }

More behavior may be added to the desugarer later.

AUTHOR

Top

Ricardo Signes <rjbs@cpan.org>

COPYRIGHT AND LICENSE

Top


Email-MIME-Kit documentation Contained in the Email-MIME-Kit distribution.

package Email::MIME::Kit::Role::ManifestDesugarer;
BEGIN {
  $Email::MIME::Kit::Role::ManifestDesugarer::VERSION = '2.102010';
}
use Moose::Role;
# ABSTRACT: helper for desugaring manifests


my $ct_desugar;
$ct_desugar = sub {
  my ($self, $content) = @_;

  for my $thing (qw(alternatives attachments)) {
    for my $part (@{ $content->{ $thing } }) {
      my $headers = $part->{header} ||= [];
      if (my $type = delete $part->{type}) {
        confess "specified both type and content_type attribute"
          if $part->{attributes}{content_type};

        $part->{attributes}{content_type} = $type;
      }

      $self->$ct_desugar($part);
    }
  }
};

around read_manifest => sub {
  my ($orig, $self, @args) = @_;
  my $content = $self->$orig(@args);

  $self->$ct_desugar($content);

  return $content;
};

no Moose::Role;
1;

__END__