/[suikacvs]/test/html-webhacc/WebHACC/Input.pm
Suika

Diff of /test/html-webhacc/WebHACC/Input.pm

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

revision 1.2 by wakaba, Sun Jul 20 16:53:10 2008 UTC revision 1.5 by wakaba, Mon Jul 21 12:56:34 2008 UTC
# Line 2  package WebHACC::Input; Line 2  package WebHACC::Input;
2  use strict;  use strict;
3    
4  sub new ($) {  sub new ($) {
5    return bless {id_prefix => ''}, shift;    return bless {}, shift;
6  } # new  } # new
7    
8  sub id_prefix ($;$) {  sub id_prefix ($) { '' }
9    if (@_ > 1) {  
10      if (defined $_[1]) {  sub nested ($) { 0 }
11        $_[0]->{id_prefix} = ''.$_[1];  
12    sub subdocument_index ($) { 0 }
13    
14    sub full_subdocument_index ($) { 0 }
15    
16    sub generate_info_section ($$) {
17      my $self = shift;
18      
19      my $result = shift;
20      my $out = $result->output;
21    
22      $out->start_section (id => 'document-info', title => 'Information');
23      $out->start_tag ('dl');
24    
25      $out->dt ('Request URL');
26      $out->start_tag ('dd');
27      $out->url ($self->{request_uri});
28    
29      $out->dt ('Document URL'); ## TODO: HTML5 "document's address"?
30      $out->start_tag ('dd');
31      $out->url ($self->{uri}, id => 'anchor-document-url');
32      $out->script (q[
33          document.title = '<'
34              + document.getElementById ('anchor-document-url').href + '> \\u2014 '
35              + document.title;
36      ]);
37    
38      if (defined $self->{s}) {
39        $out->dt ('Base URL');
40        $out->start_tag ('dd');
41        $out->url ($self->{base_uri});
42        
43        $out->dt ('Internet Media Type');
44        $out->start_tag ('dd');
45        $out->code ($self->{media_type}, class => 'MIME', lang => 'en');
46        if ($self->{media_type_overridden}) {
47          $out->nl_text ('... overridden');
48        } elsif (defined $self->{official_type}) {
49          if ($self->{media_type} eq $self->{official_type}) {
50            #
51          } else {
52            $out->nl_text ('... sniffed, official type is #',
53                           text => $self->{official_type});
54          }
55      } else {      } else {
56        $_[0]->{id_prefix} = '';        $out->nl_text ( '... sniffed');
57      }      }
   }  
58    
59    return $_[0]->{id_prefix};      $out->dt ('Character Encoding');
60  } # id_prefix      $out->start_tag ('dd');
61        if (defined $self->{charset}) {
62  sub nested ($;$) {        $out->code ($self->{charset}, class => 'charset', lang => 'en');
   if (@_ > 1) {  
     if ($_[1]) {  
       $_[0]->{nested} = 1;  
63      } else {      } else {
64        delete $_[0]->{nested};        $out->nl_text ('(unknown)');
65      }      }
66        $out->nl_text ('... overridden') if $self->{charset_overridden};
67    
68        $out->dt ($self->{is_char_string} ? 'Character Length' : 'Byte Length');
69        ## TODO: formatting
70        $out->start_tag ('dd');
71        my $length = length $self->{s};
72        $out->text ($length . ' ');
73        $out->nl_text (($self->{is_char_string} ? 'character' : 'byte') .
74                       ($length == 1 ? '' : 's'));
75    }    }
76    
77    return $_[0]->{nested};    $out->end_tag ('dl');
78  } # nested    $out->end_section;
79    } # generate_info_section
80    
81  sub generate_transfer_sections ($$) {  sub generate_transfer_sections ($$) {
82    my $self = shift;    my $self = shift;
# Line 77  not be the real header.</p> Line 126  not be the real header.</p>
126    $out->end_section;    $out->end_section;
127  } # generate_http_header_section  } # generate_http_header_section
128    
129    package WebHACC::Input::Subdocument;
130    push our @ISA, 'WebHACC::Input';
131    
132    sub new ($$) {
133      my $self = bless {}, shift;
134      $self->{subdocument_index} = shift;
135      return $self;
136    } # new
137    
138    sub id_prefix ($) {
139      return 'subdoc-' . shift->full_subdocument_index . '-';
140    } # id_prefix
141    
142    sub nested ($) { 1 }
143    
144    sub subdocument_index ($) {
145      return shift->{subdocument_index};
146    } # subdocument_index
147    
148    sub full_subdocument_index ($) {
149      my $self = shift;
150      my $parent = $self->{parent_input}->full_subdocument_index;
151      if ($parent) {
152        return $parent . '.' . $self->{subdocument_index};
153      } else {
154        return $self->{subdocument_index};
155      }
156    } # full_subdocument_index
157    
158    sub start_section ($$) {
159      my $self = shift;
160    
161      my $result = shift;
162      my $out = $result->output;
163    
164      my $index = $self->full_subdocument_index;
165      $out->start_section (id => $self->id_prefix,
166                           title => qq[Subdocument #],
167                           short_title => 'Sub #',
168                           text => $index);
169    } # start_section
170    
171    sub end_section ($$) {
172      $_[1]->output->end_section;
173    } # end_section
174    
175    sub generate_info_section ($$) {
176      my $self = shift;
177    
178      my $result = shift;
179      my $out = $result->output;
180    
181      $out->start_section (id => 'document-info', title => 'Information');
182      $out->start_tag ('dl');
183    
184      $out->dt ('Internet Media Type');
185      $out->start_tag ('dd');
186      $out->code ($self->{media_type}, code => 'MIME', lang => 'en');
187    
188      if (defined $self->{container_node}) {
189        $out->dt ('Container Node');
190        $out->start_tag ('dd');
191        my $original_input = $out->input;
192        $out->input ($self->{parent_input});
193        $out->node_link ($self->{container_node});
194        $out->input ($original_input);
195      }
196    
197      $out->dt ('Base URL');
198      $out->start_tag ('dd');
199      $out->url ($self->{base_uri});
200    
201      $out->end_tag ('dl');
202      $out->end_section;
203    } # generate_info_section
204    
205  package WebHACC::Input::Error;  package WebHACC::Input::Error;
206  push our @ISA, 'WebHACC::Input';  push our @ISA, 'WebHACC::Input';
207    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.5

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24