17 |
require Message::Header; |
require Message::Header; |
18 |
use overload '""' => sub {shift->stringify}; |
use overload '""' => sub {shift->stringify}; |
19 |
|
|
20 |
|
%DEFAULT = ( |
21 |
|
encoding_after_encode => '*default', |
22 |
|
encoding_before_decode => '*default', |
23 |
|
hook_encode_string => #sub {shift; (value => shift, @_)}, |
24 |
|
\&Message::Util::encode_body_string, |
25 |
|
hook_decode_string => #sub {shift; (value => shift, @_)}, |
26 |
|
\&Message::Util::decode_body_string, |
27 |
|
); |
28 |
|
|
29 |
=head2 Message::Body::TextPlain->new ([%option]) |
=head2 Message::Body::TextPlain->new ([%option]) |
30 |
|
|
31 |
Returns new Message::Body::TextPlain instance. Some options can be |
Returns new Message::Body::TextPlain instance. Some options can be |
53 |
my $self = bless {option => {@_}}, $class; |
my $self = bless {option => {@_}}, $class; |
54 |
for (keys %DEFAULT) {$self->{option}->{$_} ||= $DEFAULT{$_}} |
for (keys %DEFAULT) {$self->{option}->{$_} ||= $DEFAULT{$_}} |
55 |
$self->header ($self->{option}->{header}); |
$self->header ($self->{option}->{header}); |
56 |
$self->{body} = $body; |
my %s = &{$self->{option}->{hook_decode_string}} ($self, $body, type => 'body'); |
57 |
|
$self->{body} = $s{value}; |
58 |
$self; |
$self; |
59 |
} |
} |
60 |
|
|
102 |
sub stringify ($;%) { |
sub stringify ($;%) { |
103 |
my $self = shift; |
my $self = shift; |
104 |
my %OPT = @_; |
my %OPT = @_; |
105 |
my ($body) = (scalar $self->{body}); |
my (%e) = &{$self->{option}->{hook_encode_string}} ($self, |
106 |
$body .= "\n" unless $body =~ /\n$/; |
$self->{body}, type => 'body'); |
107 |
$body; |
$e{value} .= "\n" unless $e{value} =~ /\n$/; |
108 |
|
$e{value}; |
109 |
} |
} |
110 |
sub as_string ($;%) {shift->stringify (@_)} |
sub as_string ($;%) {shift->stringify (@_)} |
111 |
|
|