This started off entitled: "issues attempting to use Apache::Admin::Config->save()".
I seem to have fewer and fewer questions around here these days. Once again, stumped for too long, yet writing this out worked me through the steps to resolve this question for myself.
Apparently you can not apply a string substitution on a scalar on the same line where you assign its value to another scalar, or what gets assigned to the result of the string substitution (in my case a 1 for true). Though perhaps they could be wrapped in parens to control priority, don't know.
And I get reminded again to Keep it Simple. So thanks perlmonks for being here, where my last several questions have been aborted by working through this process in a similar way.
at a bash prompt I see:
hesco@marcus8:~/sandbox$ grep `whoami` /etc/passwd
hesco:x:1000:1000:Hugh Esco,,,:/home/hesco:/bin/bash
hesco@marcus8:~/sandbox$ ls -al t/
total 61
drwxr-xr-x 6 hesco hesco 736 2012-01-22 14:38 .
drwxr-xr-x 11 hesco hesco 856 2011-12-24 21:29 ..
hesco@marcus8:~/sandbox$ ls -al t/conf/
total 13
drwxr-xr-x 6 hesco hesco 280 2012-01-22 13:50 .
drwxr-xr-x 6 hesco hesco 736 2012-01-22 14:38 ..
hesco@marcus8:~/sandbox$ ls -al t/conf/etc/
total 0
drwxr-xr-x 3 hesco hesco 72 2011-07-02 00:57 .
drwxr-xr-x 6 hesco hesco 280 2012-01-22 13:50 ..
hesco@marcus8:~/sandbox$ ls -al t/conf/etc/apache2/
total 1
drwxr-xr-x 3 hesco hesco 80 2011-07-02 00:57 .
drwxr-xr-x 3 hesco hesco 72 2011-07-02 00:57 ..
hesco@marcus8:~/sandbox$ ls -al t/conf/etc/apache2/sites-available/
total 18
drwxr-xr-x 11 hesco hesco 480 2012-01-22 13:50 .
drwxr-xr-x 3 hesco hesco 80 2011-07-02 00:57 ..
hesco@marcus8:~/sandbox$ ls -al t/conf/etc/apache2/sites-available/tes
+t_suite/
total 1
drwxr-xr-x 2 hesco hesco 48 2012-01-22 13:51 .
drwxr-xr-x 11 hesco hesco 480 2012-01-22 13:50 ..
and when running my test script, as indicated, I get:
hesco@marcus8:~/sandbox$ perl t/14-ymd_provision_apache.t
snip
Use of uninitialized value $parent_directory in substitution (s///) at
+ lib/Apache.pm line 139.
Use of uninitialized value $parent_directory in concatenation (.) or s
+tring at lib/Apache.pm line 140.
We hope we can write to: at lib/Apache.pm line 140.
Use of uninitialized value $parent_directory in -w at lib/Apache.pm li
+ne 141.
not ok 33 - We got an anticipated result for our new apache vhost path
+.
# Failed test 'We got an anticipated result for our new apache vhost
+ path.'
# at t/14-ymd_provision_apache.t line 64.
# got: 'ERROR: user - 1000 is unable to create t/conf/etc/apa
+che2/sites-available/test_suite/test.example.org'
# expected: 't/conf/etc/apache2/sites-available/test_suite/test.ex
+ample.org'
# File [ERROR: user - 1000 is unable to create t/conf/etc/apache2/site
+s-available/test_suite/test.example.org] does not exist
from code which looks like this:
my $new_vhost_path = "$apache_vhost_base_path/" . $site->{'vhost_ser
+ver_name'};
if( -e $new_vhost_path ){
return 'ERROR: will not overwrite an existing configuration file:'
+ . $new_vhost_path;
} else {
my $parent_directory = $new_vhost_path =~ s,^(.*)/(.*),$1,;
warn "We hope we can write to: $parent_directory ";
if( -w $parent_directory ){
warn "We apparently believe that we can write to: $parent_direct
+ory \n";
$self->{'apache'}->save( $new_vhost_path, '-reformat' );
return $new_vhost_path;
} else {
return 'ERROR: user - ' . $> . ' is unable to create ' . $new_vh
+ost_path;
}
}
}
FYI: $self->{'apache'}, in this case isa(Apache::Admin::Config)
And this resolves the bug . . .
- my $parent_directory = $new_vhost_path =~ s,^(.*)/(.*),$1,;
+ my $parent_directory = $new_vhost_path;
+ $parent_directory =~ s,^(.*)/.*$,$1,;
warn "We hope we can write to: $parent_directory ";
. . . made apparent by informative debug messages.