/[suikacvs]/messaging/manakai/lib/Message/Field/AngleQuoted.pm
Suika

Contents of /messaging/manakai/lib/Message/Field/AngleQuoted.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Sun Jun 23 12:10:15 2002 UTC (22 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +2 -4 lines
2002-06-23  Wakaba <w@suika.fam.cx>

	* AngleQuoted.pm (%REG): Don't define regex locally.
	(Moved to Message::Util).
	* ContentType.pm, Date.pm, UA.pm,
	ValueParams.pm: Fix some codes not to be warned
	as 'Use of uninitialized value'.
	* Structured.pm 
	(header_default_charset, header_default_charset_input):
	New options.

1 wakaba 1.1
2     =head1 NAME
3    
4     Message::Field::AngleQuoted --- A Perl Module for Internet Message
5     Header Field Bodies filled with a URI
6    
7     =cut
8    
9     package Message::Field::AngleQuoted;
10     use strict;
11     require 5.6.0;
12     use re 'eval';
13     use vars qw(%DEFAULT @ISA %REG $VERSION);
14 wakaba 1.2 $VERSION=do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
15 wakaba 1.1 require Message::Field::Structured;
16     push @ISA, qw(Message::Field::Structured);
17    
18     %REG = %Message::Util::REG;
19    
20     =head1 CONSTRUCTORS
21    
22     The following methods construct new objects:
23    
24     =over 4
25    
26     =cut
27    
28     %DEFAULT = (
29     -_MEMBERS => [qw|display_name keyword|],
30     -_METHODS => [qw|display_name value
31     comment_add comment_delete comment_item
32     comment_count|],
33     -allow_empty => 0,
34     -comment_to_display_name => 0,
35     #encoding_after_encode
36     #encoding_before_decode
37     #field_param_name
38     #field_name
39     #hook_encode_string
40     #hook_decode_string
41     -output_angle_bracket => 1,
42     -output_comment => 1,
43     -output_display_name => 1,
44     -output_keyword => 0,
45     #parse_all
46     -unsafe_rule_of_display_name => 'NON_http_attribute_char_wsp',
47     -unsafe_rule_of_keyword => 'NON_http_attribute_char_wsp',
48     -use_comment => 1,
49     -use_comment_in_angle => 0,
50     -use_display_name => 1,
51     -use_keyword => 0,
52     );
53    
54     sub _init ($;%) {
55     my $self = shift;
56     my %options = @_;
57     my $DEFAULT = Message::Util::make_clone (\%DEFAULT);
58     $self->SUPER::_init (%$DEFAULT, %options);
59     }
60    
61     =item $uri = Message::Field::URI->new ([%options])
62    
63     Constructs a new object. You might pass some options as parameters
64     to the constructor.
65    
66     =cut
67    
68     ## Inherited
69    
70     =item $uri = Message::Field::URI->parse ($field-body, [%options])
71    
72     Constructs a new object with given field body. You might pass
73     some options as parameters to the constructor.
74    
75     =cut
76    
77     sub parse ($$;%) {
78     my $class = shift;
79     my $self = bless {}, $class;
80     my $body = shift;
81     $self->_init (@_);
82     my ($value, $dname, @comment, $keyword);
83     ($body, @comment)
84     = $self->Message::Util::delete_comment_to_array ($body,
85     -use_angle_quoted => $self->{option}->{use_comment_in_angle}? 0: 1,
86     )
87     if $self->{option}->{use_comment};
88     if ($body =~ /($REG{angle_qcontent})?$REG{M_angle_quoted}/) {
89     ($dname, $value) = ($1, $2);
90     $dname =~ s/^$REG{WSP}+//; $dname =~ s/$REG{WSP}+$//;
91     $dname = $self->Message::Util::decode_quoted_string ($dname);
92     } elsif ($self->{option}->{use_keyword}
93     && $body =~ /^$REG{FWS}($REG{atext_dot})$REG{FWS}$/) {
94     #$keyword = Message::Util::remove_meaningless_wsp ($1);
95     $keyword = $1; $keyword =~ tr/\x09\x20//d;
96     } else {
97     $value = $body;
98     }
99     $self->_save_value ($value, $dname, \@comment, keyword => $keyword);
100     $self;
101     }
102    
103     ## $self->_save_value ($value, $display_name, \@comment)
104     sub _save_value ($$\@%) {
105     my $self = shift;
106     my ($v, $dn, $comment, %misc) = @_;
107     $self->{comment} = $comment;
108     $self->{value} = $v;
109     $self->{display_name} = $dn;
110     $self->{keyword} = $misc{keyword};
111     }
112    
113     sub value ($;$%) {
114     my $self = shift;
115     my $value = shift;
116     if (defined $value) {
117     $self->{value} = $value;
118     }
119     $self->{value};
120     }
121    
122     sub display_name ($;$%) {
123     my $self = shift;
124     my $dname = shift;
125     if (defined $dname) {
126     $self->{display_name} = $dname;
127     }
128     $self->{display_name};
129     }
130    
131    
132     sub stringify ($;%) {
133     my $self = shift;
134     my %o = @_; my %option = %{$self->{option}};
135     for (grep {/^-/} keys %o) {$option{substr ($_, 1)} = $o{$_}}
136     my %v = $self->_stringify_value (\%option);
137     my ($dn, $as, $cm) = ('', '', '');
138     if (length $v{keyword}) {
139     if ($option{output_keyword}) {
140     my %s = &{$option{hook_encode_string}} ($self, $v{keyword}, type => 'phrase');
141     $as = Message::Util::quote_unsafe_string
142     ($s{value}, unsafe => $option{unsafe_rule_of_keyword});
143     } else {
144     $as = '('. $self->Message::Util::encode_ccontent ($v{keyword}) .')';
145     }
146     } else {
147     if (length ($v{value}) == 0 && !$option{allow_empty}) {
148     return '';
149     }
150     if (length $v{display_name}) {
151     if ($option{use_display_name} && $option{output_display_name}) {
152     my %s = &{$option{hook_encode_string}} ($self,
153     $v{display_name}, type => 'phrase');
154     $dn = Message::Util::quote_unsafe_string
155     ($s{value}, unsafe => $option{unsafe_rule_of_display_name}) . ' ';
156     } elsif ($option{use_comment} && $option{output_comment}) {
157     $dn = ' ('. $self->Message::Util::encode_ccontent ($v{display_name}) .')';
158     }
159     } elsif ($option{comment_to_display_name}
160     && $option{use_display_name} && $option{output_display_name}) {
161     my $fullname = ${$v{comment}}[0]; $option{_comment_min} = 1;
162     if (length $fullname) {
163     my %s = &{$option{hook_encode_string}} ($self, $fullname, type => 'phrase');
164     $dn = Message::Util::quote_unsafe_string
165     ($s{value}, unsafe => $option{unsafe_rule_of_display_name}) . ' ';
166     }
167     }
168    
169     if ($option{output_angle_bracket}) {
170     $as = '<' . $v{value} . '>';
171     } else {
172     $as = $v{value};
173     }
174     }
175     if ($option{use_comment} && $option{output_comment}) {
176     $cm = $self->_comment_stringify (\%option);
177     $cm = ' ' . $cm if $cm;
178     if ($dn && !($option{use_display_name} && $option{output_display_name})) {
179     $cm = $dn . $cm; $dn = '';
180     }
181     }
182     $dn . $as . $cm;
183     }
184     *as_string = \&stringify;
185    
186     ## $self->_stringify_value (\%option)
187     sub _stringify_value ($\%) {
188     my $self = shift;
189     my $option = shift;
190     my %r;
191     $r{value} = ''.$self->{value};
192     $r{display_name} = $self->{display_name};
193     $r{comment} = $self->{comment};
194     $r{keyword} = $self->{keyword};
195     %r;
196     }
197    
198     ## $self->_option_recursive (\%argv)
199     sub _option_recursive ($\%) {
200     my $self = shift;
201     my $o = shift;
202     eval { $self->{value}->option (%$o) if ref $self->{value} };
203     }
204    
205     =head1 LICENSE
206    
207     Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>.
208    
209     This program is free software; you can redistribute it and/or modify
210     it under the terms of the GNU General Public License as published by
211     the Free Software Foundation; either version 2 of the License, or
212     (at your option) any later version.
213    
214     This program is distributed in the hope that it will be useful,
215     but WITHOUT ANY WARRANTY; without even the implied warranty of
216     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
217     GNU General Public License for more details.
218    
219     You should have received a copy of the GNU General Public License
220     along with this program; see the file COPYING. If not, write to
221     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
222     Boston, MA 02111-1307, USA.
223    
224     =head1 CHANGE
225    
226     See F<ChangeLog>.
227 wakaba 1.2 $Date: 2002/06/15 07:15:59 $
228 wakaba 1.1
229     =cut
230    
231     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24