App-CamelPKI

 view release on metacpan or  search on metacpan

lib/App/CamelPKI/SysV/Apache.pm  view on Meta::CPAN

}

=head2 _wait_for($sub)

Waits until $sub, a CODE reference called without arguments in scalar
context, returns true; but waits no more than L</async_timeout>
seconds.  Returns whatever $sub returned the last time it was called.

=cut

sub _wait_for {
    my ($self, $sub) = @_;
    my $retval;
    for(1 .. $self->async_timeout) {
        last if $retval = $sub->();
        sleep(1);
    }
    return $retval;
}

=head2 _write_config_file()

Writes the configuration file into the path returned by
L</_config_file>.

=cut

sub _write_config_file {
    my ($self) = @_;

    # TODO: refrain from overwriting the file when it is more recent
    # than App/PKI/SysV/Apache.pm, so as to cut some slack to wise-guy
    # sysadmins.

    my $banner = <<'BANNER';
# Automatically generated Apache configuration file.
# Do not edit - Your changes will be lost.  Repeat:
#  ____                      _              _ _ _   _
# |  _ \  ___    _ __   ___ | |_    ___  __| (_) |_| |
# | | | |/ _ \  | '_ \ / _ \| __|  / _ \/ _` | | __| |
# | |_| | (_) | | | | | (_) | |_  |  __/ (_| | | |_|_|
# |____/ \___/  |_| |_|\___/ \__|  \___|\__,_|_|\__(_)
#
# See "perldoc App::CamelPKI::SysV::Apache".
BANNER

    my $homedir   = $self->{homedir};
    my $port      = $self->https_port;
    my $pidfile   = $self->_pid_filename;
    my $certfile  = $self->_certificate_filename;
    my $keyfile   = $self->_key_filename;
    my $ca_bundle = $self->_ca_bundle_filename;
    my $error_log = $self->_error_log_filename;

    # Propagate -Iblib/lib to the Apache server, so that it can load
    # Camel-PKI from the build directory if needed.
    my $perlswitches;
    if (my @blibs = grep { m/\bblib\W+lib\b/ } @INC) {
        my $perlincs = join(" ", map { "-I$_" } @blibs);
        $perlswitches = <<"PERLSWITCHES";
# As seen on http://www.catalystframework.org/calendar/2005/7:
PerlSwitches $perlincs
PERLSWITCHES
    }

    # FIXME: this is Gentoo- and  Edgy-specific.
    #TODO : refactor for using the App::Info::HTTP :)
    my %module_paths =
        (alias => "/usr/lib/apache2/modules/mod_alias.so",
         perl => "/usr/lib/apache2/modules/mod_perl.so",
         php5 => "/usr/lib/apache2/modules/libphp5.so",
         ssl  => "/usr/lib/apache2/modules/mod_ssl.so",
         mime  => "/usr/lib/apache2/modules/mod_mime.so",
        );
    my @mods_to_configure = grep { $self->_has_module_built_in($_) }
   		(keys %module_paths);
    push @mods_to_configure, qw(perl ssl); # Unconditionally needed

    my $phpstuff = "";
    if (is_installed_and_has_php_support()) {
    	if (defined(my $phpdir = $self->test_php_directory)) {
        	push(@mods_to_configure, "php5", "alias", "mime");
        	$phpstuff = <<"PHPSTUFF";
#### PHP test directory
Alias /t/php "$phpdir"
<location /t/php>
  AddType application/x-httpd-php .php
</location>
PHPSTUFF
    	}
    }

    my $modmime= "";
    if (grep { $_ eq "mime" } @mods_to_configure) {
    	$modmime = <<"MODMIME";
### Attic: mod_mime boilerplate configuration
# We basically don't use this, unfortunately both Ubuntu's
# and Gentoo's Apaches have default configurations that do
# not match the actual filesystem layout :-(
TypesConfig /etc/mime.types
MODMIME
    }

    my $loadmodules = join("", map { <<"LOADMODULE" }
LoadModule ${_}_module ${\$module_paths{$_}}
LOADMODULE
	    (grep { ! $self->_has_module_built_in("$_") }
             @mods_to_configure));

    my $catalyststuff = "";
    $catalyststuff = <<"CATALYST_STUFF" if $self->has_camel_pki();
#### Main application configuration
PerlModule App::CamelPKI
<LocationMatch "^(?!/t/)">
        SetHandler          modperl
        PerlResponseHandler App::CamelPKI
</LocationMatch>
CATALYST_STUFF

    write_file($self->_config_filename, <<"CONFIG");
$banner



( run in 2.076 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )