#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Config::General; use Test::Most tests => 6; use lib qw ( lib ); use_ok('My::NewModule::Apache'); my $apache_config_path = 't/conf/etc/apache2/sites-available'; my $virtual_host_name = 'cg.example.com'; my $virtual_host_conf_name = $virtual_host_name . '.conf'; my $config_file = "$apache_config_path/$virtual_host_conf_name"; is($config_file,'t/conf/etc/apache2/sites-available/cg.example.com.conf',"Our config file is: $config_file"); my $conf = Config::General->new( -ConfigFile => "$config_file", 'ApacheCompatible' => 1 ); # can_ok($conf,'params'); my %config = $conf->getall; # warn Dumper( \%config ); my $new_virtual_host_name = 'www.our_new_site.com'; my $new_config_conf_file = "$apache_config_path/$new_virtual_host_name"; my $new_virtual_host_conf_name = $new_virtual_host_name . '.conf'; foreach my $key (keys %{$config{'VirtualHost'}->{'*:80'}}){ if(ref $config{'VirtualHost'}->{'*:80'}->{$key} eq 'HASH'){ # skip this for the moment } else { $config{'VirtualHost'}->{'*:80'}->{$key} =~ s/$virtual_host_name/$new_virtual_host_name/; } } # warn Dumper( \%config ); my $new_conf = $conf->save_file( "$new_config_conf_file", \%config );