Subject: | new method ...Apache::doc_root returns DocumentRoot |
Attached is a patch to the 0.52 distro which adds a method doc_root()
to the HTTPD::Apache module. It scans the httpd.conf and returns the
(first instance of) DocumentRoot. This allows the user to know where
HTML files can be installed.
--
- - Martin 'Kingpin' Thurn
Subject: | doc_root.patch |
Only in .: Build
Only in .: Build.bat
Only in .: Makefile
Only in .: _build
Only in .: blib
Only in .: doc_root.patch
diff -crw ..\Orig\App-Info-0.52/lib/App/Info/HTTPD/Apache.pm ./lib/App/Info/HTTPD/Apache.pm
*** ..\Orig\App-Info-0.52/lib/App/Info/HTTPD/Apache.pm Mon Aug 13 14:24:54 2007
--- ./lib/App/Info/HTTPD/Apache.pm Mon Oct 15 08:15:00 2007
***************
*** 44,50 ****
use App::Info::Util;
use vars qw(@ISA $VERSION);
@ISA = qw(App::Info::HTTPD);
! $VERSION = '0.52';
use constant WIN32 => $^O eq 'MSWin32';
my $u = App::Info::Util->new;
--- 44,50 ----
use App::Info::Util;
use vars qw(@ISA $VERSION);
@ISA = qw(App::Info::HTTPD);
! $VERSION = '0.521';
use constant WIN32 => $^O eq 'MSWin32';
my $u = App::Info::Util->new;
***************
*** 777,790 ****
# config file in the future.
my @regexen = (qr/^\s*User\s+(.*)$/,
qr/^\s*Group\s+(.*)$/,
! qr/^\s*Port\s+(.*)$/ );
! my ($usr, $grp, $prt) = $u->multi_search_file($conf, @regexen);
# Issue a warning if we couldn't find the user and group.
$self->error("Cannot parse user from file '$conf'") unless $usr;
$self->error("Cannot parse group from file '$conf'") unless $grp;
$self->error("Cannot parse port from file '$conf'") unless $prt;
# Assign them anyway.
! @{$self}{qw(user group port)} = ($usr, $grp, $prt);
};
sub user {
--- 777,793 ----
# config file in the future.
my @regexen = (qr/^\s*User\s+(.*)$/,
qr/^\s*Group\s+(.*)$/,
! qr/^\s*Port\s+(.*)$/,
! qr/^\s*DocumentRoot\s+"?([^"]+)"?\s*$/,
! );
! my ($usr, $grp, $prt, $droot) = $u->multi_search_file($conf, @regexen);
# Issue a warning if we couldn't find the user and group.
$self->error("Cannot parse user from file '$conf'") unless $usr;
$self->error("Cannot parse group from file '$conf'") unless $grp;
$self->error("Cannot parse port from file '$conf'") unless $prt;
+ $self->error("Cannot parse DocumentRoot from file '$conf'") unless $droot;
# Assign them anyway.
! @{$self}{qw(user group port doc_root)} = ($usr, $grp, $prt, $droot);
};
sub user {
***************
*** 908,913 ****
--- 911,972 ----
##############################################################################
+ =head3 doc_root
+
+ Returns the local physical path where web pages are stored. This
+ value is collected from Apache configuration file as returned by
+ C<conf_file()>.
+
+ B<Events:>
+
+ =over 4
+
+ =item info
+
+ Searching for Apache configuration file
+
+ Executing `httpd -V`
+
+ Parsing Apache configuration file
+
+ =item error
+
+ No Apache config file found
+
+ Cannot parse user from file
+
+ Cannot parse group from file
+
+ Cannot parse port from file
+
+ Cannot parse DocumentRoot from file
+
+ =item unknown
+
+ Location of httpd.conf file?
+
+ Enter DocumentRoot actual directory
+
+ =back
+
+ =cut
+
+ sub doc_root {
+ my $self = shift;
+ return unless $self->{executable};
+ $parse_conf_file->($self) unless exists $self->{doc_root};
+ # Handle an unknown value.
+ $self->{doc_root} =
+ $self->unknown( key => 'doc root',
+ prompt => 'Enter DocumentRoot actual directory',
+ callback => $is_dir,
+ error => "Not a directory")
+ unless $self->{doc_root};
+ return $self->{doc_root};
+ } # doc_root
+
+ ##############################################################################
+
=head3 executable
my $executable = $apache->executable;
diff -crw ..\Orig\App-Info-0.52/t/apache2.t ./t/apache2.t
*** ..\Orig\App-Info-0.52/t/apache2.t Mon Aug 13 14:24:54 2007
--- ./t/apache2.t Mon Oct 15 08:15:00 2007
***************
*** 3,9 ****
# $Id: apache2.t 2802 2006-04-09 18:11:40Z theory $
use strict;
! use Test::More tests => 31;
use File::Spec::Functions;
BEGIN { use_ok('App::Info::HTTPD::Apache') }
--- 3,9 ----
# $Id: apache2.t 2802 2006-04-09 18:11:40Z theory $
use strict;
! use Test::More tests => 32;
use File::Spec::Functions;
BEGIN { use_ok('App::Info::HTTPD::Apache') }
***************
*** 66,68 ****
--- 66,69 ----
is( $apache->home_url, 'http://httpd.apache.org/', 'Get home URL' );
is( $apache->download_url, 'http://www.apache.org/dist/httpd/',
'Get download URL' );
+ is( $apache->doc_root, '/test/doc/root', 'Test doc_root');
Only in ./t: scripts
diff -crw ..\Orig\App-Info-0.52/t/testlib/httpd.conf ./t/testlib/httpd.conf
*** ..\Orig\App-Info-0.52/t/testlib/httpd.conf Mon Aug 13 14:24:54 2007
--- ./t/testlib/httpd.conf Mon Oct 15 08:15:00 2007
***************
*** 1,3 ****
--- 1,4 ----
Port 80
User nobody
Group nobody
+ DocumentRoot "/test/doc/root"