Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dispatcher minimal, avec chargement config globale dans conf/act.ini
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
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
local.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[general] | ||
conferences = 2004 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
PerlPassEnv ACTHOME | ||
PerlModule Act::Dispatcher; | ||
|
||
PerlTransHandler Act::Dispatcher::trans_handler | ||
|
||
<Location /> | ||
SetHandler "perl-script" | ||
</Location> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |