~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/Engine/Legacy.pm

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See bottom of file for license and copyright information
 
2
 
 
3
=begin TML
 
4
 
 
5
---+!! package Foswiki::Engine::Legacy
 
6
 
 
7
This engine supports legacy bin scripts that don't use
 
8
$Foswiki::cfg{SwitchBoard} yet.
 
9
 
 
10
It redefines Foswiki::Request::new and Foswiki::Response::new, so request and
 
11
response objects are singletons, making it possible to the engine finalization
 
12
phase invoked from the END block happens.
 
13
 
 
14
=cut
 
15
 
 
16
package Foswiki::Engine::Legacy;
 
17
use strict;
 
18
 
 
19
our @ISA;
 
20
my ( $request, $response );
 
21
 
 
22
BEGIN {
 
23
    if ( $ENV{GATEWAY_INTERFACE} ) {
 
24
        require Foswiki::Engine::CGI;
 
25
        @ISA = qw(Foswiki::Engine::CGI);
 
26
    }
 
27
    else {
 
28
        require Foswiki::Engine::CLI;
 
29
        @ISA = qw(Foswiki::Engine::CLI);
 
30
    }
 
31
    no warnings 'redefine';
 
32
    require Foswiki::Request;
 
33
    my $req_new = \&Foswiki::Request::new;
 
34
    *Foswiki::Request::new = sub {
 
35
        if ( defined $request ) {
 
36
            return $request;
 
37
        }
 
38
        else {
 
39
            return $request = $req_new->(@_);
 
40
        }
 
41
    };
 
42
    require Foswiki::Response;
 
43
    my $res_new = \&Foswiki::Response::new;
 
44
    *Foswiki::Response::new = sub {
 
45
        if ( defined $response ) {
 
46
            return $response;
 
47
        }
 
48
        else {
 
49
            return $response = $res_new->(@_);
 
50
        }
 
51
    };
 
52
    require Foswiki::EngineException;
 
53
}
 
54
 
 
55
sub new {
 
56
    my $this = shift;
 
57
    $this = $this->SUPER::new(@_);
 
58
    $this->prepare();
 
59
    return $this;
 
60
}
 
61
 
 
62
END {
 
63
    $Foswiki::engine->finalize( $response, $request )
 
64
      if ref($response) && $response->isa('Foswiki::Response');
 
65
    ( $request, $response ) = ();
 
66
}
 
67
 
 
68
1;
 
69
__DATA__
 
70
# Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/
 
71
#
 
72
# Copyright (C) 2008-2009 Foswiki Contributors. Foswiki Contributors
 
73
# are listed in the AUTHORS file in the root of this distribution.
 
74
# NOTE: Please extend that file, not this notice.
 
75
#
 
76
# Additional copyrights apply to some or all of the code in this
 
77
# file as follows:
 
78
#
 
79
# Copyright (C) 1999-2007 Peter Thoeny, peter@thoeny.org
 
80
# and TWiki Contributors. All Rights Reserved. TWiki Contributors
 
81
# are listed in the AUTHORS file in the root of this distribution.
 
82
#
 
83
# This module is based/inspired on Catalyst framework. Refer to
 
84
#
 
85
# http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7010/lib/Catalyst.pm
 
86
#
 
87
# for credits and liscence details.
 
88
#
 
89
# This program is free software; you can redistribute it and/or
 
90
# modify it under the terms of the GNU General Public License
 
91
# as published by the Free Software Foundation; either version 2
 
92
# of the License, or (at your option) any later version. For
 
93
# more details read LICENSE in the root of this distribution.
 
94
#
 
95
# This program is distributed in the hope that it will be useful,
 
96
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
97
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
98
#
 
99
# As per the GPL, removal of this notice is prohibited.