=head1 NAME Message::Body::TextPlain Perl module =head1 DESCRIPTION Perl module for text/plain media type. =cut package Message::Body::TextPlain; use strict; use vars qw($VERSION %DEFAULT); $VERSION=do{my @r=(q$Revision: 1.3 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; require Message::Header; use overload '""' => sub {shift->stringify}; %DEFAULT = ( encoding_after_encode => '*default', encoding_before_decode => '*default', hook_encode_string => #sub {shift; (value => shift, @_)}, \&Message::Util::encode_body_string, hook_decode_string => #sub {shift; (value => shift, @_)}, \&Message::Util::decode_body_string, ); =head2 Message::Body::TextPlain->new ([%option]) Returns new Message::Body::TextPlain instance. Some options can be specified as hash. =cut sub new ($;%) { my $class = shift; my $self = bless {option => {@_}}, $class; for (keys %DEFAULT) {$self->{option}->{$_} ||= $DEFAULT{$_}} $self; } =head2 Message::Body::TextPlain->parse ($body, [%option]) Returns a new Message::Body::TextPlain with given body object. Some options can be specified as hash. =cut sub parse ($$;%) { my $class = shift; my $body = shift; my $self = bless {option => {@_}}, $class; for (keys %DEFAULT) {$self->{option}->{$_} ||= $DEFAULT{$_}} $self->header ($self->{option}->{header}); my %s = &{$self->{option}->{hook_decode_string}} ($self, $body, type => 'body'); $self->{body} = $s{value}; $self; } =head2 $self->header ([$new_header]) =cut sub header ($;$) { my $self = shift; my $new_header = shift; if (ref $new_header) { $self->{header} = $new_header; } elsif ($new_header) { $self->{header} = Message::Header->parse ($new_header); } unless ($self->{header}) { $self->{header} = new Message::Header; } $self->{header}; } =head2 $self->body ([$new_body]) Returns C
as string unless $new_body. Set $new_body instead of current C. =cut sub body ($;$) { my $self = shift; my $new_body = shift; if ($new_body) { $self->{body} = $new_body; } $self->{body}; } =head2 $self->stringify ([%option]) Returns the C as a string. =cut sub stringify ($;%) { my $self = shift; my %OPT = @_; my (%e) = &{$self->{option}->{hook_encode_string}} ($self, $self->{body}, type => 'body'); $e{value} .= "\n" unless $e{value} =~ /\n$/; $e{value}; } sub as_string ($;%) {shift->stringify (@_)} =head2 $self->option ($option_name) Returns/set (new) value of the option. =cut sub option ($$;$) { my $self = shift; my ($name, $newval) = @_; if ($newval) { $self->{option}->{$name} = $newval; } $self->{option}->{$name}; } sub clone ($) { my $self = shift; my $clone = new Message::Entity; $clone->{body} = Message::Util::make_clone ($self->{body}); $clone; } =head1 SEE ALSO RFC 822