| 1 |
wakaba |
1.1 |
|
| 2 |
|
|
=head1 NAME
|
| 3 |
|
|
|
| 4 |
|
|
Message::Body::TextPlain Perl module
|
| 5 |
|
|
|
| 6 |
|
|
=head1 DESCRIPTION
|
| 7 |
|
|
|
| 8 |
|
|
Perl module for text/plain media type.
|
| 9 |
|
|
|
| 10 |
|
|
=cut
|
| 11 |
|
|
|
| 12 |
|
|
package Message::Body::TextPlain;
|
| 13 |
|
|
use strict;
|
| 14 |
|
|
use vars qw($VERSION %DEFAULT);
|
| 15 |
|
|
$VERSION=do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
|
| 16 |
|
|
|
| 17 |
|
|
require Message::Header;
|
| 18 |
|
|
use overload '""' => sub {shift->stringify};
|
| 19 |
|
|
|
| 20 |
|
|
=head2 Message::Body::TextPlain->new ([%option])
|
| 21 |
|
|
|
| 22 |
|
|
Returns new Message::Body::TextPlain instance. Some options can be
|
| 23 |
|
|
specified as hash.
|
| 24 |
|
|
|
| 25 |
|
|
=cut
|
| 26 |
|
|
|
| 27 |
|
|
sub new ($;%) {
|
| 28 |
|
|
my $class = shift;
|
| 29 |
|
|
my $self = bless {option => {@_}}, $class;
|
| 30 |
|
|
for (keys %DEFAULT) {$self->{option}->{$_} ||= $DEFAULT{$_}}
|
| 31 |
|
|
$self;
|
| 32 |
|
|
}
|
| 33 |
|
|
|
| 34 |
|
|
=head2 Message::Body::TextPlain->parse ($body, [%option])
|
| 35 |
|
|
|
| 36 |
|
|
Returns a new Message::Body::TextPlain with given body
|
| 37 |
|
|
object. Some options can be specified as hash.
|
| 38 |
|
|
|
| 39 |
|
|
=cut
|
| 40 |
|
|
|
| 41 |
|
|
sub parse ($$;%) {
|
| 42 |
|
|
my $class = shift;
|
| 43 |
|
|
my $body = shift;
|
| 44 |
|
|
my $self = bless {option => {@_}}, $class;
|
| 45 |
|
|
for (keys %DEFAULT) {$self->{option}->{$_} ||= $DEFAULT{$_}}
|
| 46 |
|
|
$self->header ($self->{option}->{header});
|
| 47 |
|
|
$self->{body} = $body;
|
| 48 |
|
|
$self;
|
| 49 |
|
|
}
|
| 50 |
|
|
|
| 51 |
|
|
=head2 $self->header ([$new_header])
|
| 52 |
|
|
|
| 53 |
|
|
|
| 54 |
|
|
=cut
|
| 55 |
|
|
|
| 56 |
|
|
sub header ($;$) {
|
| 57 |
|
|
my $self = shift;
|
| 58 |
|
|
my $new_header = shift;
|
| 59 |
|
|
if (ref $new_header) {
|
| 60 |
|
|
$self->{header} = $new_header;
|
| 61 |
|
|
} elsif ($new_header) {
|
| 62 |
|
|
$self->{header} = Message::Header->parse ($new_header);
|
| 63 |
|
|
}
|
| 64 |
|
|
unless ($self->{header}) {
|
| 65 |
|
|
$self->{header} = new Message::Header;
|
| 66 |
|
|
}
|
| 67 |
|
|
$self->{header};
|
| 68 |
|
|
}
|
| 69 |
|
|
|
| 70 |
|
|
=head2 $self->body ([$new_body])
|
| 71 |
|
|
|
| 72 |
|
|
Returns C<body> as string unless $new_body.
|
| 73 |
|
|
Set $new_body instead of current C<body>.
|
| 74 |
|
|
|
| 75 |
|
|
=cut
|
| 76 |
|
|
|
| 77 |
|
|
sub body ($;$) {
|
| 78 |
|
|
my $self = shift;
|
| 79 |
|
|
my $new_body = shift;
|
| 80 |
|
|
if ($new_body) {
|
| 81 |
|
|
$self->{body} = $new_body;
|
| 82 |
|
|
}
|
| 83 |
|
|
$self->{body};
|
| 84 |
|
|
}
|
| 85 |
|
|
|
| 86 |
|
|
=head2 $self->stringify ([%option])
|
| 87 |
|
|
|
| 88 |
|
|
Returns the C<body> as a string.
|
| 89 |
|
|
|
| 90 |
|
|
=cut
|
| 91 |
|
|
|
| 92 |
|
|
sub stringify ($;%) {
|
| 93 |
|
|
my $self = shift;
|
| 94 |
|
|
my %OPT = @_;
|
| 95 |
|
|
my ($body) = (scalar $self->{body});
|
| 96 |
|
|
$body .= "\n" unless $body =~ /\n$/;
|
| 97 |
|
|
$body;
|
| 98 |
|
|
}
|
| 99 |
|
|
sub as_string ($;%) {shift->stringify (@_)}
|
| 100 |
|
|
|
| 101 |
|
|
=head2 $self->option ($option_name)
|
| 102 |
|
|
|
| 103 |
|
|
Returns/set (new) value of the option.
|
| 104 |
|
|
|
| 105 |
|
|
=cut
|
| 106 |
|
|
|
| 107 |
|
|
sub option ($$;$) {
|
| 108 |
|
|
my $self = shift;
|
| 109 |
|
|
my ($name, $newval) = @_;
|
| 110 |
|
|
if ($newval) {
|
| 111 |
|
|
$self->{option}->{$name} = $newval;
|
| 112 |
|
|
}
|
| 113 |
|
|
$self->{option}->{$name};
|
| 114 |
|
|
}
|
| 115 |
|
|
|
| 116 |
|
|
=head1 SEE ALSO
|
| 117 |
|
|
|
| 118 |
|
|
RFC 822 <urn:ietf:rfc:822>,
|
| 119 |
|
|
RFC 2046 <urn:ietf:rfc:2046>, RFC 2646 <urn:ietf:rfc:2646>.
|
| 120 |
|
|
|
| 121 |
|
|
=head1 LICENSE
|
| 122 |
|
|
|
| 123 |
|
|
Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>.
|
| 124 |
|
|
|
| 125 |
|
|
This program is free software; you can redistribute it and/or modify
|
| 126 |
|
|
it under the terms of the GNU General Public License as published by
|
| 127 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
| 128 |
|
|
(at your option) any later version.
|
| 129 |
|
|
|
| 130 |
|
|
This program is distributed in the hope that it will be useful,
|
| 131 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 132 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 133 |
|
|
GNU General Public License for more details.
|
| 134 |
|
|
|
| 135 |
|
|
You should have received a copy of the GNU General Public License
|
| 136 |
|
|
along with this program; see the file COPYING. If not, write to
|
| 137 |
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
| 138 |
|
|
Boston, MA 02111-1307, USA.
|
| 139 |
|
|
|
| 140 |
|
|
=head1 CHANGE
|
| 141 |
|
|
|
| 142 |
|
|
See F<ChangeLog>.
|
| 143 |
|
|
$Date: 2002/03/13 15:10:21 $
|
| 144 |
|
|
|
| 145 |
|
|
=cut
|
| 146 |
|
|
|
| 147 |
|
|
1;
|