App-Acmeman

 view release on metacpan or  search on metacpan

lib/App/Acmeman/Apache/Layout/slackware.pm  view on Meta::CPAN

	$last_loadmodule->fixup_lines($app->filename => 1);
    }

    if (!$letsencrypt_macro_loaded && !$need_macro_module) {
	if ($stop_search) {
	    debug(3, "Will insert \"$include_text\" before $stop_search");
	    $self->add_command($stop_search, \&_insert_directive_before,
			       $include_text);
	} else {
	    debug(3, "Will insert \"$include_text\" after $last_loadmodule");
	    $self->add_command($last_loadmodule, \&_insert_directive_after,
			       $include_text);
        }	    
    }

    $self->run_commands;
}

sub add_command {
    my ($self, $locus, $command, $text) = @_;
    my $file = ($locus->filenames)[0];
    my $line = ($locus->filelines($file))[0];

    push @{$self->{_edits}{$file}}, { line => $line, command => $command, text => $text };
}

sub run_commands {
    my ($self) = @_;
    foreach my $file (keys %{$self->{_edits}}) {
	$self->run_commands_for_file($file);
    }
    $self->apache_modules(undef);
}

sub run_commands_for_file {
    my ($self, $file) = @_;
    my @commands = sort { $a->{line} <=> $b->{line} } @{$self->{_edits}{$file}};

    my $app = new Apache::Config::Preproc(
        $file,
	'-no-comment-grouping',
        -expand => [ 'locus' ])
	or do {
	    error("can't parse apache configuration file $file: $Apache::Admin::Config::ERROR");
	    return;
    };

    foreach my $node ($app->select) {
	last if (!@commands);
	my $line = ($node->locus->filelines(($node->locus->filenames)[0]))[0];
	if ($commands[0]->{line} == $line) {
	    my $cmd = shift @commands;
	    $self->${\ $cmd->{command} }($app, $node, $cmd->{text});
	}
    }

    if (@commands) {
	error((0+@commands) . " left unmatched in edit queue for file $file");
	error("$file left unchanged");
    } else {
	my $backup_name = backup_copy($app->filename, error => \my $error);
	if ($backup_name) {
	    debug(1, "modifying ".$app->filename."; prior version saved in $backup_name");
	} elsif ($error) {
	    error("can't backup ".$app->filename.": $error");
	    error("file left unchanged");
	    return;
	}
	$app->save;
    }
}

sub _replace_directive_at {
    my ($self, $app, $node, $text) = @_;
    $self->_insert_directive_after($app, $node, $text);
    $node->delete;
}

sub _insert_directive_after {
    my ($self, $app, $node, $text) = @_;
    my ($name, $value) = split /\s+/, $text, 2;
    $app->add('directive', $name, $value, -after => $node);
}

sub _insert_directive_before {
    my ($self, $app, $node, $text) = @_;
    my ($name, $value) = split /\s+/, $text, 2;
    $app->add('directive', $name, $value, -before => $node);
}


1;

	    



( run in 1.112 second using v1.01-cache-2.11-cpan-4ef0a570458 )