You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axkit-dev@xml.apache.org by ma...@sergeant.org on 2006/08/16 05:40:47 UTC

[SVN] [88] DirectoryIndex moved to uri_to_file

Revision: 88
Author:   matt
Date:     2006-08-16 03:40:24 +0000 (Wed, 16 Aug 2006)

Log Message:
-----------
DirectoryIndex moved to uri_to_file
uri_to_file documented

Modified Paths:
--------------
    trunk/etc/axkit.conf.sample
    trunk/lib/AxKit2/Config/Global.pm
    trunk/lib/AxKit2/Config/Location.pm
    trunk/lib/AxKit2/Config/Server.pm
    trunk/lib/AxKit2/Config.pm
    trunk/plugins/uri_to_file

Modified: trunk/etc/axkit.conf.sample
===================================================================
--- trunk/etc/axkit.conf.sample	2006-08-16 03:39:00 UTC (rev 87)
+++ trunk/etc/axkit.conf.sample	2006-08-16 03:40:24 UTC (rev 88)
@@ -16,7 +16,6 @@
     
     Port   8000
     DocumentRoot   demo
-    DirectoryIndex index.html
     
     Plugin uri_to_file
     Plugin serve_cgi
@@ -24,6 +23,8 @@
     
     CGI_Match  .*\.(pl|cgi)$
     
+    DirectoryIndex index.html
+    
     <Location /stylesheets>
         # CSS
         DocumentRoot demo/stylesheets

Modified: trunk/lib/AxKit2/Config/Global.pm
===================================================================
--- trunk/lib/AxKit2/Config/Global.pm	2006-08-16 03:39:00 UTC (rev 87)
+++ trunk/lib/AxKit2/Config/Global.pm	2006-08-16 03:40:24 UTC (rev 88)
@@ -34,12 +34,6 @@
     $self->{ConsoleAddr};
 }
 
-sub dirindex {
-    my $self = shift;
-    @_ and $self->{DirectoryIndex} = shift;
-    $self->{DirectoryIndex};
-}
-
 sub add_plugin {
     my $self = shift;
     push @{$self->{Plugins}}, shift;

Modified: trunk/lib/AxKit2/Config/Location.pm
===================================================================
--- trunk/lib/AxKit2/Config/Location.pm	2006-08-16 03:39:00 UTC (rev 87)
+++ trunk/lib/AxKit2/Config/Location.pm	2006-08-16 03:40:24 UTC (rev 88)
@@ -44,12 +44,6 @@
     $self->{DocumentRoot} || $self->server->docroot;
 }
 
-sub dirindex {
-    my $self = shift;
-    @_ and $self->{DirectoryIndex} = shift;
-    $self->{DirectoryIndex} || $self->server->dirindex;
-}
-
 sub add_plugin {
     my $self = shift;
     push @{$self->{Plugins}}, shift;

Modified: trunk/lib/AxKit2/Config/Server.pm
===================================================================
--- trunk/lib/AxKit2/Config/Server.pm	2006-08-16 03:39:00 UTC (rev 87)
+++ trunk/lib/AxKit2/Config/Server.pm	2006-08-16 03:40:24 UTC (rev 88)
@@ -48,12 +48,6 @@
     $self->{DocumentRoot} || $self->global->docroot;
 }
 
-sub dirindex {
-    my $self = shift;
-    @_ and $self->{DirectoryIndex} = shift;
-    $self->{DirectoryIndex} || $self->global->dirindex;
-}
-
 sub add_plugin {
     my $self = shift;
     push @{$self->{Plugins}}, shift;

Modified: trunk/lib/AxKit2/Config.pm
===================================================================
--- trunk/lib/AxKit2/Config.pm	2006-08-16 03:39:00 UTC (rev 87)
+++ trunk/lib/AxKit2/Config.pm	2006-08-16 03:40:24 UTC (rev 88)
@@ -14,7 +14,6 @@
     Plugin => [\&TAKE1, sub { my $conf = shift; AxKit2::Client->load_plugin($conf, $_[0]); $conf->add_plugin($_[0]); }],
     Port   => [\&TAKE1, sub { my $conf = shift; $conf->port($_[0]) }],
     DocumentRoot => [\&TAKE1, sub { my $conf = shift; $conf->docroot($_[0]) }],
-    DirectoryIndex => [\&TAKE1, sub { my $conf = shift; $conf->dirindex($_[0]) }],
     ConsolePort => [\&TAKE1, sub { my $conf = shift; $conf->isa('AxKit2::Config::Global') || die "ConsolePort only allowed at global level"; $conf->console_port($_[0]) }],
     ConsoleAddr => [\&TAKE1, sub { my $conf = shift; $conf->isa('AxKit2::Config::Global') || die "ConsoleAddr only allowed at global level"; $conf->console_addr($_[0]) }],
     PluginDir  => [\&TAKE1, sub { my $conf = shift; $conf->plugin_dir($_[0]) }],

Modified: trunk/plugins/uri_to_file
===================================================================
--- trunk/plugins/uri_to_file	2006-08-16 03:39:00 UTC (rev 87)
+++ trunk/plugins/uri_to_file	2006-08-16 03:40:24 UTC (rev 88)
@@ -1,8 +1,48 @@
 #!/usr/bin/perl -w
 
+=head1 NAME
+
+uri_to_file - Convert URIs to filenames, and  other critical stuff
+
+=head1 SYNOPSIS
+
+  Plugin uri_to_file
+  
+  # optionally:
+  DirectoryIndex index.html
+
+=head1 DESCRIPTION
+
+This plugin provides the filename for a given URI. It is absolutely required
+that you load this plugin if you wish to serve files off the filesystem, or else
+re-implement its functionality somehow.
+
+It also splits off the path_info off the URI, provides a redirect when a
+directory without a "/" is requested, and implements C<DirectoryIndex> (see below).
+
+=head1 CONFIG
+
+=head2 DirectoryIndex STRING
+
+A filename to append to directory requests. If the file exists then it will be
+the filename used instead of the directory itself.
+
+=cut
+
 use File::Spec::Functions qw(canonpath catfile);
 use AxKit2::Utils qw(uri_decode);
 
+sub init {
+    my $self = shift;
+    $self->register_config('DirectoryIndex', sub { $self->set_dirindex(@_) });
+}
+
+sub set_dirindex {
+    my ($self, $config, $value) = @_;
+    my $key = $self->plugin_name . '::dirindex';
+    $config->notes($key, $value);
+}
+
 sub hook_uri_translation {
     my ($self, $hd, $uri) = @_;
     
@@ -41,8 +81,10 @@
 EOT
             return DONE;
         }
-        my $filepath = catfile($path, $self->config->dirindex);
-        $path = $filepath if -f $filepath;
+        if (my $dirindex = $self->config->notes($self->plugin_name . '::dirindex')) {
+            my $filepath = catfile($path, $dirindex);
+            $path = $filepath if -f $filepath;
+        }
     }
     
     my $path_info = '';