summaryrefslogtreecommitdiff
path: root/XOrg/ConfigGenerator.pm
blob: a136113e8504d2ded52c2d4bd390e3c3c5f6112c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl

# Copyright © 2011 by Red Hat, Inc.
#                                                                            
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# 
# Authors: Peter Hutterer <peter.hutterer@redhat.com>


=head1 NAME

XOrg::ConfigGenerator - simple parent class for configuration generators

=head1 DESCRIPTION

This module provides a few functions common to configuration generators.

=cut

package XOrg::ConfigGenerator;

use warnings;
use strict;
use Carp;
use Data::Dumper;

=head2 B<$config-E<gt>print>

Return a textual representation of this object.
=cut
sub print {
	return "Override me";
}

=head2 B<$config-E<gt>save([$filename)>

Save configuration to $filename;
=cut
sub save {
	my $self = shift;
	my $filename = shift;

	if (defined $self->DEFAULT_CONFIG_FILE) {
		$filename = $self->DEFAULT_CONFIG_FILE if not defined $filename;
	}

	open FILE, "> $filename" or return 0;
	print FILE $self->print;
	close FILE;
	return 1;
}


=head2 B<$config-E<gt>add_to_placeholder($placeholder, $replacement)>

Replace $placehoder with $replacement, leaving one placeholder instance for
the next replacement.

Returns the replaced text.
=cut
sub add_to_placeholder {
	my $self = shift;
	my $str = shift;
	my $placeholder = shift;
	my $replacement = shift;

	$str =~ s/(→$placeholder←)/$replacement\n	$1/;

	return $str;
}

sub replace {
	my $self = shift;
	my $str = shift;
	my $replace = shift;

	for (keys %{$replace}) {
		$str =~ s/→$_←/$replace->{$_}/;
	}
	return $str;
}


=head2 B<$config-E<gt>purify($string)

Removes any placeholders from the string and returns it.
=cut
sub purify {
	my $self = shift;
	my $str = shift;
	$str =~ s/→\w+←//g;
	return $str;
}

1;

# vim: set noexpandtab shiftwidth=8 tabstop=8: