Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the App-Info CPAN distribution.

Report information
The Basics
Id: 30009
Status: resolved
Priority: 0/
Queue: App-Info

People
Owner: Nobody in particular
Requestors: MTHURN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 0.54



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"
Subject: Re: [rt.cpan.org #30009] new method ...Apache::doc_root returns DocumentRoot
Date: Mon, 15 Oct 2007 15:42:37 -0700
To: bug-App-Info [...] rt.cpan.org
From: "David E. Wheeler" <billing [...] kineticode.com>
On Oct 15, 2007, at 05:27, Martin Thurn via RT wrote: Show quoted text
> 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.
Thanks. Any chance you could send a unified diff (diff -u)? BTW, SVN access is here: https://svn.kineticode.com/App-Info/trunk/ Thanks, David
Here is a unified diff. I'm a CVS guru but I don't understand Subversion. Sounds stupid but I guess you can't teach an old dog new tricks 8-) -- - - Martin 'Kingpin' Thurn
Only in .: Build Only in .: Build.bat Only in .: Makefile Only in .: _build Only in .: blib Only in .: doc_root.patch diff -ru ../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 2007-08-13 14:24:54.000000000 -0400 +++ ./lib/App/Info/HTTPD/Apache.pm 2007-10-15 08:15:00.000000000 -0400 @@ -44,7 +44,7 @@ use App::Info::Util; use vars qw(@ISA $VERSION); @ISA = qw(App::Info::HTTPD); -$VERSION = '0.52'; +$VERSION = '0.521'; use constant WIN32 => $^O eq 'MSWin32'; my $u = App::Info::Util->new; @@ -777,14 +777,17 @@ # 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); + 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)} = ($usr, $grp, $prt); + @{$self}{qw(user group port doc_root)} = ($usr, $grp, $prt, $droot); }; sub user { @@ -908,6 +911,62 @@ ############################################################################## +=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 -ru ../Orig/App-Info-0.52/t/apache2.t ./t/apache2.t --- ../Orig/App-Info-0.52/t/apache2.t 2007-08-13 14:24:54.000000000 -0400 +++ ./t/apache2.t 2007-10-15 08:15:00.000000000 -0400 @@ -3,7 +3,7 @@ # $Id: apache2.t 2802 2006-04-09 18:11:40Z theory $ use strict; -use Test::More tests => 31; +use Test::More tests => 32; use File::Spec::Functions; BEGIN { use_ok('App::Info::HTTPD::Apache') } @@ -66,3 +66,4 @@ 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 -ru ../Orig/App-Info-0.52/t/testlib/httpd.conf ./t/testlib/httpd.conf --- ../Orig/App-Info-0.52/t/testlib/httpd.conf 2007-08-13 14:24:54.000000000 -0400 +++ ./t/testlib/httpd.conf 2007-10-15 08:15:00.000000000 -0400 @@ -1,3 +1,4 @@ Port 80 User nobody Group nobody +DocumentRoot "/test/doc/root"
Subject: Re: [rt.cpan.org #30009] new method ...Apache::doc_root returns DocumentRoot
Date: Wed, 14 May 2008 20:50:59 -0700
To: bug-App-Info [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Oct 15, 2007, at 18:51, Martin Thurn via RT wrote: Show quoted text
> Here is a unified diff. > I'm a CVS guru but I don't understand Subversion. Sounds stupid but I > guess you can't teach an old dog new tricks 8-)
Thanks. I've applied your patch. I'll do a release soon. Sorry for the delay! Best, David