| 1 | package OpenInteract2::Brick::CGI; | ||||||||||
| 2 | |||||||||||
| 3 | 87 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 87 | ▶ | use base qw( OpenInteract2::Brick ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 87 | ▶ | use OpenInteract2::Exception; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 87 | my %INLINED_SUBS = ( | |||||||||
| 8 | 'oi2.cgi' => 'OI2CGI', | ||||||||||
| 9 | 'oi2.fcgi' => 'OI2FCGI', | ||||||||||
| 10 | ); | ||||||||||
| 11 | |||||||||||
| 12 | 87 | ▶ | sub get_name { | ||||||||
|
Subroutine
get_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 13 | 87 | return 'cgi'; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 3 | ▶ | sub get_resources { | ||||||||
|
Subroutine
get_resources: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 17 | return ( | ||||||||||
| 18 | 3 | 'oi2.cgi' => [ 'cgi-bin oi2.cgi', 'yes' ], | |||||||||
| 19 | 'oi2.fcgi' => [ 'cgi-bin oi2.fcgi', 'yes' ], | ||||||||||
| 20 | ); | ||||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 2 | ▶ | sub load { | ||||||||
|
Subroutine
load: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||
| 24 | 2 | my ( $self, $resource_name ) = @_; | |||||||||
| 25 | 2 | my $inline_sub_name = $INLINED_SUBS{ $resource_name }; | |||||||||
| 26 | 2 | ▶ | unless ( $inline_sub_name ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | OpenInteract2::Exception->throw( | |||||||||
| 28 | "Resource name '$resource_name' not found ", | ||||||||||
| 29 | "in ", ref( $self ), "; cannot load content." ); | ||||||||||
| 30 | } | ||||||||||
| 31 | 2 | return $self->$inline_sub_name(); | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 87 | OpenInteract2::Brick->register_factory_type( get_name() => __PACKAGE__ ); | |||||||||
| 35 | |||||||||||
| 36 | =pod | ||||||||||
| 37 | |||||||||||
| 38 | =head1 NAME | ||||||||||
| 39 | |||||||||||
| 40 | OpenInteract2::Brick::CGI - Script for running OI2 as a CGI | ||||||||||
| 41 | |||||||||||
| 42 | =head1 SYNOPSIS | ||||||||||
| 43 | |||||||||||
| 44 | oi2_manage create_website --website_dir=/path/to/site | ||||||||||
| 45 | |||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||
| 47 | |||||||||||
| 48 | This class holds the script for running OI2 as a CGI. | ||||||||||
| 49 | |||||||||||
| 50 | These resources are associated with OpenInteract2 version 1.99_06. | ||||||||||
| 51 | |||||||||||
| 52 | =head2 Resources | ||||||||||
| 53 | |||||||||||
| 54 | You can grab resources individually using the names below and | ||||||||||
| 55 | C<load_resource()> and C<copy_resources_to()>, or you can copy all the | ||||||||||
| 56 | resources at once using C<copy_all_resources_to()> -- see | ||||||||||
| 57 | L<OpenInteract2::Brick> for details. | ||||||||||
| 58 | |||||||||||
| 59 | =over 4 | ||||||||||
| 60 | |||||||||||
| 61 | |||||||||||
| 62 | =item B<oi2.cgi> | ||||||||||
| 63 | |||||||||||
| 64 | =item B<oi2.fcgi> | ||||||||||
| 65 | |||||||||||
| 66 | |||||||||||
| 67 | =back | ||||||||||
| 68 | |||||||||||
| 69 | =head1 COPYRIGHT | ||||||||||
| 70 | |||||||||||
| 71 | Copyright (c) 2005 Chris Winters. All rights reserved. | ||||||||||
| 72 | |||||||||||
| 73 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 74 | it under the same terms as Perl itself. | ||||||||||
| 75 | |||||||||||
| 76 | =head1 AUTHORS | ||||||||||
| 77 | |||||||||||
| 78 | |||||||||||
| 79 | Chris Winters E<lt>chris@cwinters.comE<gt> | ||||||||||
| 80 | |||||||||||
| 81 | |||||||||||
| 82 | =cut | ||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | 1 | ▶ | sub OI2CGI { | ||||||||
|
Subroutine
OI2CGI: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 86 | 1 | return <<'SOMELONGSTRING'; | |||||||||
| 87 | #!/usr/bin/perl | ||||||||||
| 88 | |||||||||||
| 89 | # $Id: oi2.cgi,v 1.5 2003/08/21 03:45:01 lachoy Exp $ | ||||||||||
| 90 | |||||||||||
| 91 | use strict; | ||||||||||
| 92 | use Log::Log4perl; | ||||||||||
| 93 | use OpenInteract2::Auth; | ||||||||||
| 94 | use OpenInteract2::Controller; | ||||||||||
| 95 | use OpenInteract2::Context; | ||||||||||
| 96 | use OpenInteract2::Request; | ||||||||||
| 97 | use OpenInteract2::Response; | ||||||||||
| 98 | |||||||||||
| 99 | { | ||||||||||
| 100 | my $website_dir = '[% website_dir %]'; | ||||||||||
| 101 | my $l4p_conf = File::Spec->catfile( | ||||||||||
| 102 | $website_dir, 'conf', 'log4perl.conf' ); | ||||||||||
| 103 | Log::Log4perl::init( $l4p_conf ); | ||||||||||
| 104 | my $ctx = OpenInteract2::Context->create( | ||||||||||
| 105 | { website_dir => $website_dir }); | ||||||||||
| 106 | $ctx->assign_request_type( 'cgi' ); | ||||||||||
| 107 | $ctx->assign_response_type( 'cgi' ); | ||||||||||
| 108 | |||||||||||
| 109 | my $response = OpenInteract2::Response->new(); | ||||||||||
| 110 | my $request = OpenInteract2::Request->new(); | ||||||||||
| 111 | |||||||||||
| 112 | OpenInteract2::Auth->new()->login(); | ||||||||||
| 113 | |||||||||||
| 114 | my $controller = eval { | ||||||||||
| 115 | OpenInteract2::Controller->new( $request, $response ) | ||||||||||
| 116 | }; | ||||||||||
| 117 | if ( $@ ) { | ||||||||||
| 118 | $response->content( $@ ); | ||||||||||
| 119 | } | ||||||||||
| 120 | else { | ||||||||||
| 121 | $controller->execute; | ||||||||||
| 122 | } | ||||||||||
| 123 | $response->send; | ||||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | SOMELONGSTRING | ||||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | 1 | ▶ | sub OI2FCGI { | ||||||||
|
Subroutine
OI2FCGI: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 130 | 1 | return <<'SOMELONGSTRING'; | |||||||||
| 131 | #!/usr/bin/perl | ||||||||||
| 132 | |||||||||||
| 133 | # $Id: oi2.fcgi,v 1.1 2005/02/18 03:29:40 lachoy Exp $ | ||||||||||
| 134 | |||||||||||
| 135 | use strict; | ||||||||||
| 136 | use FCGI; | ||||||||||
| 137 | use File::Spec::Functions qw( catfile ); | ||||||||||
| 138 | use Log::Log4perl; | ||||||||||
| 139 | use OpenInteract2::Auth; | ||||||||||
| 140 | use OpenInteract2::Controller; | ||||||||||
| 141 | use OpenInteract2::Context; | ||||||||||
| 142 | use OpenInteract2::Request; | ||||||||||
| 143 | use OpenInteract2::Response; | ||||||||||
| 144 | |||||||||||
| 145 | { | ||||||||||
| 146 | my $website_dir = '[% website_dir %]'; | ||||||||||
| 147 | my $l4p_conf = File::Spec->catfile( | ||||||||||
| 148 | $website_dir, 'conf', 'log4perl.conf' ); | ||||||||||
| 149 | Log::Log4perl::init( $l4p_conf ); | ||||||||||
| 150 | my $ctx = OpenInteract2::Context->create({ | ||||||||||
| 151 | website_dir => $website_dir | ||||||||||
| 152 | }); | ||||||||||
| 153 | $ctx->assign_request_type( 'cgi' ); | ||||||||||
| 154 | $ctx->assign_response_type( 'cgi' ); | ||||||||||
| 155 | |||||||||||
| 156 | my $fcgi_request = FCGI::Request(); | ||||||||||
| 157 | |||||||||||
| 158 | while ( $fcgi_request->Accept() >= 0 ) { | ||||||||||
| 159 | my $response = OpenInteract2::Response->new(); | ||||||||||
| 160 | my $request = OpenInteract2::Request->new(); | ||||||||||
| 161 | |||||||||||
| 162 | OpenInteract2::Auth->new()->login(); | ||||||||||
| 163 | |||||||||||
| 164 | my $controller = eval { | ||||||||||
| 165 | OpenInteract2::Controller->new( $request, $response ) | ||||||||||
| 166 | }; | ||||||||||
| 167 | if ( $@ ) { | ||||||||||
| 168 | $response->content( $@ ); | ||||||||||
| 169 | } | ||||||||||
| 170 | else { | ||||||||||
| 171 | $controller->execute; | ||||||||||
| 172 | } | ||||||||||
| 173 | $response->send; | ||||||||||
| 174 | $ctx->cleanup_request; | ||||||||||
| 175 | } | ||||||||||
| 176 | } | ||||||||||
| 177 | |||||||||||
| 178 | SOMELONGSTRING | ||||||||||
| 179 | } | ||||||||||
| 180 | |||||||||||