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

Diff of /messaging/manakai/lib/Message/Field/ValueParams.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by wakaba, Tue Mar 26 05:31:56 2002 UTC revision 1.4 by wakaba, Sun Mar 31 13:11:55 2002 UTC
# Line 23  $VERSION=do{my @r=(q$Revision$=~/\d+/g); Line 23  $VERSION=do{my @r=(q$Revision$=~/\d+/g);
23  %DEFAULT = (  %DEFAULT = (
24    use_parameter_extension       => 1,    use_parameter_extension       => 1,
25    value_default => '',    value_default => '',
26    value_no_regex        => qr/(?!)/,    value_no_regex        => qr/(?!)/,    ## default = (none)
27    value_regex   => qr/[\x00-\xFF]+/,    value_regex   => qr/[\x00-\xFF]+/,
28    value_unsafe_rule     => 'NON_http_token_wsp',    value_unsafe_rule     => 'NON_http_token_wsp',
   value_type    => {'*DEFAULT'  => ':none:',  
   },  
29  );  );
30    
31    ## Initialization for both C<new ()> and C<parse ()> methods.
32    sub _initialize ($;%) {
33      my $self = shift;
34      my $fname = lc $self->{option}->{field_name};
35      if ($fname eq 'link') {
36        $REG{r_nomatch} = qr/(?!)/;
37        $self->{option}->{value_unsafe_rule} = 'r_nomatch';
38        $self->{option}->{value_type}->{'*value'} = ['Message::Field::URI',
39          {field_name => $self->{option}->{field_name},
40          format => $self->{option}->{format}}];
41      }
42      $self;
43    }
44    
45  =head2 Message::Field::ValueParams->new ([%option])  =head2 Message::Field::ValueParams->new ([%option])
46    
47  Returns new Message::Field::ValueParams.  Some options can be given as hash.  Returns new Message::Field::ValueParams.  Some options can be given as hash.
# Line 122  is a reference to the object. Line 134  is a reference to the object.
134    
135  ## Hook called before returning C<value>.  ## Hook called before returning C<value>.
136  ## $self->_param_value ($name, $value);  ## $self->_param_value ($name, $value);
137  sub _param_value ($$$) {  ## -- Inherited.
   my $self = shift;  
   my $name = shift;  
   my $value = shift;  
   my $vtype = $self->{option}->{value_type}->{$name}  
            || $self->{option}->{value_type}->{'*DEFAULT'};  
   if (ref $value) {  
     return $value;  
   } elsif ($vtype eq ':none:') {  
     return $value;  
   } elsif ($value) {  
     eval "require $vtype";  
     return $vtype->parse ($value);  
   } else {  
     eval "require $vtype";  
     return $vtype->new ();  
   }  
 }  
138    
139  =head2 $self->stringify ([%option])  =head2 $self->stringify ([%option])
140    
# Line 170  sub value ($;$%) { Line 165  sub value ($;$%) {
165    if ($new_value && $new_value !~ m#$self->{option}->{value_no_regex}#) {    if ($new_value && $new_value !~ m#$self->{option}->{value_no_regex}#) {
166      $self->{value} = $new_value;      $self->{value} = $new_value;
167    }    }
168    #my $unsafe_rule = $option{unsafe_rule} || $self->{option}->{value_unsafe_rule};    $self->{value} = $self->_param_value ('*value', $self->{value});
   #$self->_quote_unsafe_string ($self->{value}, unsafe => $unsafe_rule);  
169    $self->{value};    $self->{value};
170  }  }
171    
# Line 189  sub value_as_string ($;%) { Line 183  sub value_as_string ($;%) {
183    my (%e) = &{$self->{option}->{hook_encode_string}} ($self,    my (%e) = &{$self->{option}->{hook_encode_string}} ($self,
184            $self->{value}, type => 'phrase');            $self->{value}, type => 'phrase');
185    my $unsafe_rule = $option{unsafe_rule} || $self->{option}->{value_unsafe_rule};    my $unsafe_rule = $option{unsafe_rule} || $self->{option}->{value_unsafe_rule};
186    $self->_quote_unsafe_string ($e{value}, unsafe => $unsafe_rule);    $self->_quote_unsafe_string ($e{value}, unsafe_regex => $REG{$unsafe_rule});
187  }  }
188    
189    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24