PAB3

 view release on metacpan or  search on metacpan

lib/PAB3/ModPerl/Registry.pm  view on Meta::CPAN

# =============================================================================
# Perl Application Builder
# Module: PAB3::ModPerl::Registry
# Use "perldoc PAB3::ModPerl::Registry" for documentation
# =============================================================================
package PAB3::ModPerl::Registry;

use strict;
use warnings;

use vars qw($VERSION);

BEGIN {
	$VERSION = '1.0.1';
	if( exists $ENV{'MOD_PERL_API_VERSION'}
		&& $ENV{'MOD_PERL_API_VERSION'} == 2
	) {
		require Apache2::ServerUtil;
		require Apache2::Response;
		require Apache2::RequestRec;
		require Apache2::RequestUtil;
		require Apache2::RequestIO;
		require Apache2::Log;
		require Apache2::Access;
		
		require APR::Table;
		require APR::Status;
		
		require ModPerl::Util;
		require ModPerl::Global;
	}
	elsif( exists $ENV{'MOD_PERL'} ) {
		require Apache;
		require Apache::Log;
	}
	
	require PAB3;
	require PAB3::CGI;
}

1;

sub handler : method {
    # init modperl handler
    my $class = ( @_ >= 2 ) ? shift : __PACKAGE__;
    my $r = shift;

	if( ! $PAB3::Statistic::VERSION &&
		$r->dir_config->get( 'UseStatistic' )
	) {
		require PAB3::Statistic;
	}

	# set additional variables to the environment
	&PAB3::CGI::setenv();
	
	# parse request and cookies
	&PAB3::CGI::init();
	
	$ENV{'GATEWAY_INTERFACE'} = 'CGI-ModPerl-PAB3';
	
	my $filename = $r->filename();

	my $package = $r->dir_config->get( 'Package' );
	if( ! $package ) {
		$package = __PACKAGE__ . '_' . $filename;
		$package =~ s/\W/_/go;
	}
	
	my $code = <<EOT1;
*{'$package\::_GET'} = \\\%{'PAB3::CGI::_GET'};
*{'$package\::_POST'} = \\\%{'PAB3::CGI::_POST'};
*{'$package\::_REQUEST'} = \\\%{'PAB3::CGI::_REQUEST'};
*{'$package\::_FILES'} = \\\%{'PAB3::CGI::_FILES'};
*{'$package\::_COOKIE'} = \\\%{'PAB3::CGI::_COOKIE'};
*{'$package\::header'} = \\\&{'PAB3::CGI::header'};
*{'$package\::redirect'} = \\\&{'PAB3::CGI::redirect'};
*{'$package\::setcookie'} = \\\&{'PAB3::CGI::setcookie'};
*{'$package\::print_var'} = \\\&{'PAB3::CGI::print_var'};
*{'$package\::print_r'} = \\\&{'PAB3::CGI::print_var'};
*{'$package\::encode_uri'} = \\\&{'PAB3::CGI::encode_uri'};
*{'$package\::decode_uri'} = \\\&{'PAB3::CGI::decode_uri'};
*{'$package\::encode_uri_component'} = \\\&{'PAB3::CGI::encode_uri_component'};
*{'$package\::encode_uri_component'} = \\\&{'PAB3::CGI::encode_uri_component'};
EOT1

	if( -r $filename ) {
		&PAB3::require_and_run( $filename, $package, $code, [ $r ] );
		$r->print( '' );
	}
	else {
		return 410;
	}
}

__END__

=head1 NAME

PAB3::ModPerl::Registry -
Run Perl5 scripts persistently under Apache and mod_perl inside the PAB3 CGI
environment

=head1 SYNOPSIS

  ------------
  mod_perl 1.x
  ------------
  
  # httpd.conf
  PerlModule PAB3::ModPerl::Registry
  Alias /cgi-pab/ /home/httpd/cgi-bin/
  <Location /cgi-pab>
      SetHandler perl-script
      PerlHandler PAB3::ModPerl::Registry



( run in 1.090 second using v1.01-cache-2.11-cpan-6aa56a78535 )