Skip to content

Commit

Permalink
Dispatcher minimal, avec chargement config globale dans conf/act.ini
Browse files Browse the repository at this point in the history
Les variables de act.ini peuvent être redéfinies dans conf/local.ini
pour s'accomoder des variations locales (chemins, etc)- local.ini n'est
pas sous contrôle CVS.
Je vais faire un INSTALL pour expliquer la config Apache


git-svn-id: svn://svn.mongueurs.net/act/trunk@19 67b57a05-4208-db11-a765-00306e02d86a
  • Loading branch information
Éric Cholet committed Mar 24, 2004
1 parent 4cc1638 commit 6a966fd
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions conf/.cvsignore
@@ -0,0 +1 @@
local.ini
2 changes: 2 additions & 0 deletions conf/act.ini
@@ -0,0 +1,2 @@
[general]
conferences = 2004
8 changes: 8 additions & 0 deletions conf/httpd.conf
@@ -0,0 +1,8 @@
PerlPassEnv ACTHOME
PerlModule Act::Dispatcher;

PerlTransHandler Act::Dispatcher::trans_handler

<Location />
SetHandler "perl-script"
</Location>
71 changes: 71 additions & 0 deletions lib/Act/Dispatcher.pm
@@ -0,0 +1,71 @@
use strict;
package Act::Dispatcher;

use vars qw(@ISA @EXPORT $Config);
@ISA = qw(Exporter);
@EXPORT = qw($Config);

use Apache::Constants qw(OK DECLINED);
use AppConfig qw(:expand :argcount);

# load global configuration
_load_global_config();

# main dispatch table
my %dispatch = (
coucou => sub {
$Config->r->send_http_header('text/plain');
$Config->r->print("conférence ", $Config->conference);
},
);

# translation handler
sub trans_handler
{
my $r = shift;
my @c = grep $_, split '/', $r->uri;

if ( @c >= 2
&& exists $Config->conferences->{$c[0]}
&& exists $dispatch{$c[1]}
)
{
$Config->set(conference => $c[0]);
$Config->set(action => $c[1]);
$r->push_handlers(PerlHandler => 'Act::Dispatcher::handler');
return OK;
}
return DECLINED;
}

# response handler - it all starts here.
sub handler
{
# the Apache request object
$Config->set(r => shift);

# dispatch
$dispatch{$Config->action}->();

return OK;
}

# load global configuration
sub _load_global_config
{
my $home = $ENV{ACTHOME} or die "ACTHOME environment variable isn't set\n";
$Config = AppConfig->new(
{
CREATE => 1,
GLOBAL => {
DEFAULT => "<undef>",
ARGCOUNT => ARGCOUNT_ONE,
EXPAND => EXPAND_VAR,
}
}
);
$Config->set(home => $home);
$Config->file(map "$home/conf/$_.ini", qw(act local));
$Config->set(conferences => { map { $_ => 1 } split /\s+/, $Config->general_conferences });
}
1;

0 comments on commit 6a966fd

Please sign in to comment.