summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2020-01-13 13:44:18 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2020-01-13 14:52:26 (GMT)
commit3a9980f96e6fe23b8de35556d16984d34e853b2a (patch) (side-by-side diff)
tree4b4000b88539777387f60847b758f33fe859161d
parentec2c3da9a865bd51c8766d5c25f9339738a40073 (diff)
downloadacmeman-3a9980f96e6fe23b8de35556d16984d34e853b2a.tar.gz
acmeman-3a9980f96e6fe23b8de35556d16984d34e853b2a.tar.bz2
Fix apache layout detection
* lib/App/Acmeman/Apache/Layout.pm (new): Split into two constructors: new and detect. Always pass the server parameter to the Apache::Defaults constructor. (App::Acmeman::Apache::Layout::auto): Remove. * lib/App/Acmeman/Source/Apache.pm (new): Use Layout->detect, instead of new. (server_root): Return server_root from the layout, unless it was set explicitly.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/App/Acmeman/Apache/Layout.pm100
-rw-r--r--lib/App/Acmeman/Source/Apache.pm8
2 files changed, 47 insertions, 61 deletions
diff --git a/lib/App/Acmeman/Apache/Layout.pm b/lib/App/Acmeman/Apache/Layout.pm
index 1f2027c..5c6d191 100644
--- a/lib/App/Acmeman/Apache/Layout.pm
+++ b/lib/App/Acmeman/Apache/Layout.pm
@@ -6,6 +6,8 @@ use Carp;
use File::Basename;
use feature 'state';
use App::Acmeman::Log qw(:all);
+use Apache::Defaults;
+use Carp;
sub _find_httpd {
my $httpd;
@@ -44,65 +46,60 @@ sub modules {
@$loaders;
}
-# new(NAME)
-# new()
sub new {
- my $class = shift;
-
- if (@_ == 0) {
- # Autodetect
- debug(3, "detecting Apache configuration layout");
- my $ap = new Apache::Defaults(server => $class->_find_httpd,
- on_error => 'return');
- if ($ap->status) {
- croak "unable to get Apache defaults: " . $ap->error;
- }
-
- foreach my $mod ($class->modules) {
- debug(3, "trying layout module $mod");
- my $obj;
- eval {
- $obj = $mod->new($ap);
- };
- if ($obj) {
- return $obj;
- }
- if ($@) {
- debug(3, "layout module failed: $@");
- }
- }
+ my ($class, $ap, %args) = @_;
- if ($ap) {
- return new App::Acmeman::Apache::Layout::auto($ap);
- }
+ unless ($ap->isa('Apache::Defaults')) {
+ croak "unrecognized argument";
+ }
- croak "unrecognized Apache layout";
+ my $self = bless { _defaults => $ap }, $class;
+ foreach my $kw (qw(layout_name incdir restart_command)) {
+ if (defined(my $v = delete $args{$kw})) {
+ $self->{$kw} = $v;
+ }
}
- my ($name, %args) = @_;
- if (ref($name) eq '') {
- my $mod = "$class::$name";
- my $obj;
- eval {
- require $mod;
- };
+ return $self;
+}
+
+sub detect {
+ my $class = shift;
+ my $server = $class->_find_httpd;
+
+ if (my $name = shift) {
+ my $mod = "${class}::$name";
+ eval "require $mod";
croak "undefined Apache layout $name" if ($@);
- return $mod->new;
+ my $self = $mod->new(new Apache::Defaults(server => $server), @_);
+ if (!$self) {
+ croak "can't use layout $name";
+ }
+ return $self;
}
-
- unless ($name->isa('Apache::Defaults')) {
- croak "unrecognized argument";
+
+ # Autodetect
+ debug(3, "detecting Apache configuration layout"
+ .(defined($server) ? " (using httpd binary $server)" : ''));
+ my $ap = new Apache::Defaults(server => $server, on_error => 'return');
+ if ($ap->status) {
+ croak "unable to get Apache defaults: " . $ap->error;
}
- my $self = bless { _defaults => $name }, $class;
- foreach my $kw (qw(layout_name incdir restart_command)) {
- if (defined(my $v = delete $args{$kw})) {
- $self->{$kw} = $v;
+ foreach my $mod ($class->modules) {
+ debug(3, "trying layout module $mod");
+ my $obj;
+ eval { $obj = $mod->new($ap) };
+ if ($obj) {
+ return $obj;
+ }
+ if ($@) {
+ debug(3, "layout module failed: $@");
}
}
- return $self;
-}
+ return new App::Acmeman::Apache::Layout($ap, layout_name => 'auto');
+}
sub apache { shift->{_defaults} }
@@ -181,14 +178,5 @@ sub restart_command {
sub pre_setup {}
sub post_setup {}
-
-package App::Acmeman::Apache::Layout::auto;
-my @ISA = qw(App::Acmeman::Apache::Layout);
-use App::Acmeman::Log qw(:all);
-
-sub new {
- my ($class, $ap) = @_;
- return $class->SUPER::new($ap);
-}
1;
diff --git a/lib/App/Acmeman/Source/Apache.pm b/lib/App/Acmeman/Source/Apache.pm
index 29fe24a..a9a6195 100644
--- a/lib/App/Acmeman/Source/Apache.pm
+++ b/lib/App/Acmeman/Source/Apache.pm
@@ -19,10 +19,8 @@ sub new {
my $server_root;
GetOptionsFromArray(\@_,
'server-root=s' => \$server_root);
- my $self = bless { _layout => new App::Acmeman::Apache::Layout(@_) }, $class;
- unless ($server_root) {
- $server_root = Apache::Defaults->new->server_root;
- }
+ my $layout = detect App::Acmeman::Apache::Layout(@_);
+ my $self = bless { _layout => $layout }, $class;
$self->server_root($server_root) if $server_root;
return $self;
}
@@ -132,7 +130,7 @@ sub server_root {
croak "too many arguments" if $@;
$self->{_server_root} = $v;
}
- return $self->{_server_root};
+ return $self->{_server_root} || $self->layout->apache->server_root;
}
sub mkpath {

Return to:

Send suggestions and report system problems to the System administrator.