| 1 | package Email::MIME::MobileJP::Creator; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Email::MIME; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use Email::Address::JP::Mobile; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Email::Address::Loose -override; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | sub new { | ||||||||||
| 12 | 3 | ▶ | my ($class, $to) = @_; | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 13 | 3 | ▶ | Carp::croak("missing To") unless defined $to; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | |||||||||||
| 15 | 3 | my $mail = Email::MIME->create(); | |||||||||
| 16 | 3 | my $carrier = Email::Address::JP::Mobile->new($to); | |||||||||
| 17 | 3 | my $self = bless { mail => $mail, carrier => $carrier }, $class; | |||||||||
| 18 | 3 | ▶ | if ($to) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 3 | $self->header('To' => $to); | |||||||||
| 20 | } | ||||||||||
| 21 | 3 | $self->mail->charset_set($carrier->send_encoding->mime_name); | |||||||||
| 22 | 3 | return $self; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 27 | ▶ | sub mail { $_[0]->{mail} } | ||||||||
|
Subroutine
mail: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 26 | 20 | ▶ | sub carrier { $_[0]->{carrier} } | ||||||||
|
Subroutine
carrier: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 27 | |||||||||||
| 28 | sub subject { | ||||||||||
| 29 | 6 | ▶ | my $self = shift; | ||||||||
|
Subroutine
subject: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 30 | 6 | $self->header('Subject' => @_); | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | sub body { | ||||||||||
| 34 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
body: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 35 | |||||||||||
| 36 | 4 | ▶ | if (@_==0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 2 | $self->carrier->send_encoding->decode($self->mail->body_raw()); | |||||||||
| 38 | } else { | ||||||||||
| 39 | 2 | $self->mail->body_set($self->carrier->send_encoding->encode(@_)); | |||||||||
| 40 | } | ||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | sub header { | ||||||||||
| 44 | 12 | ▶ | my ($self, $k, $v) = @_; | ||||||||
|
Subroutine
header: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 45 | 12 | ▶ | if (defined $v) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 6 | $self->mail->header_set($k, $self->carrier->mime_encoding->encode($v)); | |||||||||
| 47 | } else { | ||||||||||
| 48 | 6 | $self->carrier->mime_encoding->decode($self->mail->header_obj->header_raw($k)); | |||||||||
| 49 | } | ||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | sub add_part { | ||||||||||
| 53 | 1 | ▶ | my ($self, $body, $attributes) = @_; | ||||||||
|
Subroutine
add_part: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 54 | 1 | my $part = Email::MIME->create( | |||||||||
| 55 | body => $body, | ||||||||||
| 56 | attributes => $attributes, | ||||||||||
| 57 | ); | ||||||||||
| 58 | 1 | $self->mail->parts_add([$part]); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | sub add_text_part { | ||||||||||
| 62 | 1 | ▶ | my ($self, $body, $attributes) = @_; | ||||||||
|
Subroutine
add_text_part: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 63 | |||||||||||
| 64 | 1 | my $encoding = $self->carrier->send_encoding(); | |||||||||
| 65 | my $part = Email::MIME->create( | ||||||||||
| 66 | body => $encoding->encode($body), | ||||||||||
| 67 | attributes => { | ||||||||||
| 68 | content_type => 'text/plain', | ||||||||||
| 69 | charset => $encoding->mime_name(), | ||||||||||
| 70 | encoding => '7bit', | ||||||||||
| 71 | 1 | ▶ | %{ $attributes || +{} } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | }, | ||||||||||
| 73 | ); | ||||||||||
| 74 | 1 | $self->mail->parts_add([$part]); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | sub finalize { | ||||||||||
| 78 | 3 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
finalize: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 79 | 3 | return $self->mail; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 2 | 1; | |||||||||
| 83 | __END__ | ||||||||||