/[suikacvs]/test/cvs
Suika

Diff of /test/cvs

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

revision 1.39 by wakaba, Fri Jul 26 12:42:00 2002 UTC revision 1.42 by wakaba, Wed Nov 13 08:08:51 2002 UTC
# Line 57  push @ISA, qw(Message::Field::Structured Line 57  push @ISA, qw(Message::Field::Structured
57      #value_type      #value_type
58  );  );
59    
 ## taken from L<HTTP::Header>  
 # "Good Practice" order of HTTP message headers:  
 #    - General-Headers  
 #    - Request-Headers  
 #    - Response-Headers  
 #    - Entity-Headers  
 # (From draft-ietf-http-v11-spec-rev-01, Nov 21, 1997)  
 my @header_order = qw(  
   mail-from x-envelope-from relay-version path status  
   
    cache-control connection date pragma transfer-encoding upgrade trailer via  
   
    accept accept-charset accept-encoding accept-language  
    authorization expect from host  
    if-modified-since if-match if-none-match if-range if-unmodified-since  
    max-forwards proxy-authorization range referer te user-agent  
   
    accept-ranges age location proxy-authenticate retry-after server vary  
    warning www-authenticate  
   
    mime-version  
    allow content-base content-encoding content-language content-length  
    content-location content-md5 content-range content-type  
    etag expires last-modified content-style-type content-script-type  
    link  
   
   xref  
 );  
 my %header_order;  
   
60  =head1 CONSTRUCTORS  =head1 CONSTRUCTORS
61    
62  The following methods construct new C<Message::Header> objects:  The following methods construct new C<Message::Header> objects:
# Line 120  sub _init ($;%) { Line 90  sub _init ($;%) {
90    }    }
91    &{ $self->{option}->{hook_init_fill_options} } ($self, $self->{option});    &{ $self->{option}->{hook_init_fill_options} } ($self, $self->{option});
92    $self->_init_by_format ($self->{option}->{format}, $self->{option});    $self->_init_by_format ($self->{option}->{format}, $self->{option});
   # Make alternative representations of @header_order.  This is used  
   # for sorting.  
   my $i = 1;  
   for (@header_order) {  
       $header_order{$_} = $i++ unless $header_order{$_};  
   }  
     
93    $self->add (@new_fields, -parse => $self->{option}->{parse_all})    $self->add (@new_fields, -parse => $self->{option}->{parse_all})
94      if $#new_fields > -1;      if $#new_fields > -1;
95  }  }
# Line 137  sub _init_by_format ($$\%) { Line 100  sub _init_by_format ($$\%) {
100    if ($format =~ /http/) {    if ($format =~ /http/) {
101      $option->{ns_default_phuri} = $self->{ns}->{phname2uri}->{'x-http'};      $option->{ns_default_phuri} = $self->{ns}->{phname2uri}->{'x-http'};
102      if ($format =~ /cgi/) {      if ($format =~ /cgi/) {
103        unshift @header_order, qw(content-type location);        #unshift @header_order, qw(content-type location);
104        $option->{field_sort} = 'good-practice';        $option->{field_sort} = 'good-practice';
105        $option->{use_folding} = 0;        $option->{use_folding} = 0;
106      } else {      } else {
# Line 334  sub _item_return_value ($\$\%) { Line 297  sub _item_return_value ($\$\%) {
297      ${$_[1]}->{body};      ${$_[1]}->{body};
298    } else {    } else {
299      ${$_[1]}->{body} = $_[0]->_parse_value (${$_[1]}->{name} => ${$_[1]}->{body},      ${$_[1]}->{body} = $_[0]->_parse_value (${$_[1]}->{name} => ${$_[1]}->{body},
300        ns => ${$_[1]}->{ns});        ns => ${$_[1]}->{ns}) if $_[2]->{parse};
301      ${$_[1]}->{body};      ${$_[1]}->{body};
302    }    }
303  }  }
# Line 481  sub _value_to_arrayitem ($$$\%) { Line 444  sub _value_to_arrayitem ($$$\%) {
444      $nsuri = $value_option->{ns};      $nsuri = $value_option->{ns};
445    } elsif ($option->{ns}) {    } elsif ($option->{ns}) {
446      $nsuri = $option->{ns};      $nsuri = $option->{ns};
447    } elsif (($default_ns eq $self->{ns}->{uri2phname}->{'x-http'}    } elsif (($default_ns eq $self->{ns}->{phname2uri}->{'x-http'}
448         && $name =~ s/^([0-9]+)-//)         && $name =~ s/^([0-9]+)-//)
449      || ($name =~ s/^x-http-([0-9]+)-//i)) {     ## Numric namespace prefix, RFC 2774      || ($name =~ s/^x-http-([0-9]+)-//i)) {     ## Numric namespace prefix, RFC 2774
450      my $prefix = 0+$1;      my $prefix = 0+$1;
# Line 513  sub _value_to_arrayitem ($$$\%) { Line 476  sub _value_to_arrayitem ($$$\%) {
476        $nsuri = $default_ns;        $nsuri = $default_ns;
477        $prefix        $prefix
478          = &{ ${ &_NS_uri2package ($nsuri).'::OPTION' }{n11n_prefix} }          = &{ ${ &_NS_uri2package ($nsuri).'::OPTION' }{n11n_prefix} }
479            ($self, &_NS_uri2package ($nsuri), $one_prefix? $prefix2: $prefix1);            ($self, &_NS_uri2package ($nsuri), $one_prefix? $prefix2:
480               $prefix1);
481        $self->_ns_load_ph ($prefix);        $self->_ns_load_ph ($prefix);
482        $nsuri = $self->{ns}->{phname2uri}->{ $prefix };        $nsuri = $self->{ns}->{phname2uri}->{ $prefix };
483        if ($nsuri) {        if ($nsuri) {
484          $name = $prefix2 . '-' . $name unless $one_prefix;          $name = $prefix2 . '-' . $name unless $one_prefix;
485        } else {        } else {
486          $name = $original_prefix . $name;          unless ($one_prefix) {
487          $nsuri = $default_ns;            $prefix
488                = &{ ${ &_NS_uri2package ($nsuri).'::OPTION' }{n11n_prefix} }
489                  ($self, &_NS_uri2package ($nsuri),
490                   $self->{ns}->{uri2phname}->{ $default_ns } . '-' . $prefix1);
491              $self->_ns_load_ph ($prefix);
492              $nsuri = $self->{ns}->{phname2uri}->{ $prefix };
493              if ($nsuri) {
494                $name = $prefix2 . '-' . $name;
495              }
496            }
497            unless ($nsuri) {
498              $name = $original_prefix . $name;
499              $nsuri = $default_ns;
500            }
501        }        }
502      }      }
503    }    }
# Line 618  sub rename ($%) { Line 595  sub rename ($%) {
595    $self if defined wantarray;    $self if defined wantarray;
596  }  }
597    
598    sub resent_item ($$$;%) {
599      my $self = shift;
600      my ($index, $item_name, %option) = @_;
601      ## TODO: implement this
602    }
603    
604  =item $self->scan(\&doit)  =item $self->scan(\&doit)
605    
# Line 629  for each value. Line 611  for each value.
611  =cut  =cut
612    
613  sub _scan_sort ($\@\%) {  sub _scan_sort ($\@\%) {
614      no strict 'refs';
615    my $self = shift;    my $self = shift;
616    my ($array, $option) = @_;    my ($array, $option) = @_;
617    my $sort;    my $nspack = &_NS_uri2package ($self->{option}->{ns_default_phuri});
618    $sort = \&_header_cmp if $option->{field_sort} eq 'good-practice';    my $sort = ${ $nspack.'::OPTION' }{field_sort};
619    $sort = {$a cmp $b} if $option->{field_sort} eq 'alphabetic';    if ($option->{field_sort} eq 'good-practice' && $sort->{'good-practice'}) {
620    return ( sort $sort @$array ) if ref $sort;      return $self->Message::Header::Default::sort_good_practice ($array, $nspack, $option);
621      } elsif ($option->{field_sort} eq 'alphabetic' && $sort->{'alphabetic'}) {
622        ## TODO: How treat namespace prefix?
623        return sort {$a->{name} cmp $b->{name}} @$array;
624      }
625    @$array;    @$array;
626  }  }
627    
# Line 647  sub _n11n_field_name ($$) { Line 634  sub _n11n_field_name ($$) {
634    $s;    $s;
635  }  }
636    
 # Compare function which makes it easy to sort headers in the  
 # recommended "Good Practice" order.  
 ## taken from HTTP::Header  
 sub _header_cmp  
 {  
   my ($na, $nb) = ($a->{name}, $b->{name});  
     # Unknown headers are assign a large value so that they are  
     # sorted last.  This also helps avoiding a warning from -w  
     # about comparing undefined values.  
     $header_order{$na} = 999 unless defined $header_order{$na};  
     $header_order{$nb} = 999 unless defined $header_order{$nb};  
   
     $header_order{$na} <=> $header_order{$nb} || $na cmp $nb;  
 }  
637    
638  =head2 $self->stringify ([%option])  =head2 $self->stringify ([%option])
639    
# Line 849  sub _ns_load_ph ($$) { Line 822  sub _ns_load_ph ($$) {
822    my $name = shift;     ## normalized prefix (without HYPHEN-MINUS)    my $name = shift;     ## normalized prefix (without HYPHEN-MINUS)
823    return if $self->{ns}->{phname2uri}->{$name};    return if $self->{ns}->{phname2uri}->{$name};
824    $self->{ns}->{phname2uri}->{$name} = $NS_phname2uri{$name};    $self->{ns}->{phname2uri}->{$name} = $NS_phname2uri{$name};
825    return unless $self->{ns}->{phname2uri}->{$name};    $self->{ns}->{uri2phname}->{ $self->{ns}->{phname2uri}->{$name} } = $name;
   $self->{ns}->{uri2phname}->{$self->{ns}->{phname2uri}->{$name}} = $name;  
826  }  }
827    
828  sub _ns_associate_numerical_prefix ($) {  sub _ns_associate_numerical_prefix ($) {

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.42

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24