Any-Daemon-HTTP

 view release on metacpan or  search on metacpan

examples/apache.pl  view on Meta::CPAN


GetOptions
   'background|bg!' => \$run_opts{background}
 , 'childs|c=i'     => \$run_opts{max_childs}
 , 'group|g=s'      => \$os_opts{group}
 , 'host|h=s'       => \$net_opts{host}
 , 'pid-file|p=s'   => \$os_opts{pid_file}
 , 'user|u=s'       => \$os_opts{user}
 , 'v+'             => \$mode  # -v -vv -vvv
    or exit 1;

$run_opts{background} //= 1;

#
## initialize the daemon activities
#

# From now on, all errors and warnings are also sent to syslog,
# provided by Log::Report. Output still also to the screen.
dispatcher SYSLOG => 'syslog', accept => 'INFO-'
  , identity => 'any-httpd', facility => 'local0';

# Do not send info to the terminal anymore
#dispatcher close => 'default';

dispatcher mode => $mode, 'ALL' if $mode;

my $httpd = Any::Daemon::HTTP->new
  ( %net_opts
  , %os_opts
  , standard_headers =>
      [ X_Daemon => 'my-daemon v3'
      , X_More   => 'later'
      ]

# , proxies     =>
#    { forward_map    => 'RELAY'
#    }
  );

## Simpelest, auto-creates ::Directory
# $httpd->addVirtualHost
#   ( name      => 'test'
#   , aliases   => [$net_opts{host}]
#   , documents => '/etc'
#   );

## More complex, add one or more ::Directory's by config or object
my $vhost = $httpd->addVirtualHost
  ( name        => 'test'
  , aliases     => ['www.test.nl', 'www.example.org', $net_opts{host}, 'default']

  , directories =>
     { path           => '/'
     , location       => '/etc'
     , directory_list => 1
#    , allow          => '127.0.0.1/32'
     }

  , handlers    =>                   # Handlers run when no file is found
     { '/fake.cgi'    => \&fake_cgi  # looks like cgi, is internal function ;-)
     , '/form/submit' => \&form_in   # match all uri start with this
#    , '/'            => \&errors    # overrule default error page
     }

# , proxies     =>
  );

$httpd->run
  ( %run_opts
  );

exit 0;



( run in 0.906 second using v1.01-cache-2.11-cpan-39bf76dae61 )