| 1 | # -*- perl -*- | ||
| 2 | |||
| 3 | # | ||
| 4 | # $Id: OldHandler.pm,v 1.4 2004/04/16 23:27:35 eserte Exp $ | ||
| 5 | # Author: Slaven Rezic | ||
| 6 | # | ||
| 7 | # Copyright (C) 2003 Slaven Rezic. All rights reserved. | ||
| 8 | # This package is free software; you can redistribute it and/or | ||
| 9 | # modify it under the same terms as Perl itself. | ||
| 10 | # | ||
| 11 | # Mail: slaven@rezic.de | ||
| 12 | # WWW: http://www.rezic.de/eserte/ | ||
| 13 | # | ||
| 14 | |||
| 15 | package WebEditor::OldHandler; | ||
| 16 | |||
| 17 | use strict; | ||
| 18 | no strict 'refs'; | ||
| 19 | use vars qw($VERSION %config); | ||
| 20 | $VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/); | ||
| 21 | |||
| 22 | use Apache; | ||
| 23 | |||
| 24 | sub handler ($$) { | ||
| 25 | my($self, $r) = @_; | ||
| 26 | |||
| 27 | my $c = $self->get_wesiteinfo_config($r); | ||
| 28 | my $oc = $self->get_controller_object($c); | ||
| 29 | |||
| 30 | local $SIG{__DIE__} = $oc->get_die_handler; | ||
| 31 | $oc->handle($c, $r); | ||
| 32 | } | ||
| 33 | |||
| 34 | sub get_wesiteinfo_config { | ||
| 35 | my($self, $r) = @_; | ||
| 36 | my $wesiteinfo_file = $r->dir_config("wesiteinfo_file"); | ||
| 37 | my $wesiteinfo_class = $r->dir_config("wesiteinfo_class"); | ||
| 38 | my $c = $config{$wesiteinfo_class}; | ||
| 39 | if (!$c) { | ||
| 40 | if (!defined $wesiteinfo_file) { | ||
| 41 | $wesiteinfo_file = $wesiteinfo_class; | ||
| 42 | } | ||
| 43 | require $wesiteinfo_file; | ||
| 44 | $c = $wesiteinfo_class->get_config; | ||
| 45 | $config{$wesiteinfo_class} = $c; | ||
| 46 | } | ||
| 47 | $c; | ||
| 48 | } | ||
| 49 | |||
| 50 | sub get_controller_object { | ||
| 51 | my($self, $c) = @_; | ||
| 52 | my $controller_class = "WE_" . $c->project->name . "::OldController"; | ||
| 53 | eval q{use } . $controller_class; | ||
| 54 | if ($@) { | ||
| 55 | if ($@ =~ /Can't locate/) { | ||
| 56 | # use generic controller instead | ||
| 57 | $controller_class = "WebEditor::OldController"; | ||
| 58 | eval q{ use } . $controller_class; | ||
| 59 | die $@ if $@; | ||
| 60 | } else { | ||
| 61 | die $@; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | my $oc = $controller_class->new; | ||
| 65 | $oc; | ||
| 66 | } | ||
| 67 | |||
| 68 | 1; | ||
| 69 | |||
| 70 | __END__ |