- Timestamp:
- 11/12/08 19:06:56 (5 years ago)
- Files:
-
- 1 modified
-
docs/hidek/bench/nanoa/lib/NanoA.pm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
docs/hidek/bench/nanoa/lib/NanoA.pm
r23378 r23380 5 5 6 6 sub new { 7 my ($klass, $config , $q) = @_;7 my ($klass, $config) = @_; 8 8 bless { 9 9 config => $config, 10 query => $q,10 query => undef, 11 11 headers => { 12 12 -type => 'text/html', 13 -charset => 'utf -8',13 -charset => 'utf8', 14 14 }, 15 15 }, $klass; … … 32 32 sub query { 33 33 my $self = shift; 34 $self->{query} = shift 35 if @_; 34 unless ($self->{query}) { 35 my $cgi_klass = $self->config('cgi_klass') || 'CGI::Simple'; 36 my $cgi_path = $cgi_klass; 37 $cgi_path =~ s{::}{/}g; 38 require "$cgi_path.pm"; 39 $self->{query} = $cgi_klass->new; 40 } 36 41 $self->{query}; 37 42 } … … 66 71 } 67 72 73 sub print_header { 74 my $self = shift; 75 my $headers = $self->{headers}; 76 my $ct = 77 delete($headers->{-type}) . "; charset=" . delete($headers->{-charset}); 78 print "Content-Type: $ct\n"; 79 foreach my $n (sort keys %$headers) { 80 my $v = $headers->{$n}; 81 $n =~ s/^-//; 82 $n =~ tr/_/-/; 83 if (ref $v eq 'ARRAY') { 84 foreach my $vv (@$v) { 85 print "$n: $v\n"; 86 } 87 } else { 88 print "$n: $v\n"; 89 } 90 } 91 print "\n"; 92 } 93 68 94 package NanoA::Dispatch; 69 95 … … 74 100 my ($klass, $config) = @_; 75 101 76 my $q = $klass->build_query($config); 77 78 my $handler_path = $config->{prefix} . ($q->path_info || '/'); 102 $config->{mt_cache_dir} = $klass->default_cache_dir($config) 103 unless exists $config->{mt_cache_dir}; 104 105 my $handler_path = $config->{prefix} . ($ENV{PATH_INFO} || '/'); 79 106 $handler_path =~ s{\.\.}{}g; 80 107 $handler_path = camelize($handler_path) … … 83 110 my $handler_klass = $klass->load_handler($config, $handler_path) 84 111 || $klass->load_handler($config, $klass->not_found); 85 my $handler = $handler_klass->new($config , $q);112 my $handler = $handler_klass->new($config); 86 113 87 114 $handler->prerun(); … … 89 116 $handler->postrun(\$body); 90 117 91 print $q->header(%{$handler->headers}), $body; 92 } 93 94 sub build_query { 95 my ($klass, $config) = @_; 96 my $cgi_klass = $config->{cgi_klass} || 'CGI::Simple'; 97 my $cgi_path = $cgi_klass; 98 $cgi_path =~ s{::}{/}g; 99 require "$cgi_path.pm"; 100 $cgi_klass->new; 118 $handler->print_header(); 119 print $body; 101 120 } 102 121 … … 146 165 my ($klass, $config) = @_; 147 166 $config->{not_found} || 'NanoA/NotFound'; 167 } 168 169 sub default_cache_dir { 170 my ($klass, $config) = @_; 171 my $prefix = $config->{prefix}; 172 $prefix =~ s|/|::|g; 173 "/tmp/$prefix.$>.mt_cache"; 148 174 } 149 175
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)