Debian Codegraph @

xpp/perl_modules/Dahdi/Config/Gen/Modules.pm

raw
1 package Dahdi::Config::Gen::Modules;
2 use strict;
3
4 use Dahdi::Config::Gen qw(is_true);
5
6 sub new($$$) {
7 my $pack = shift || die;
8 my $gconfig = shift || die;
9 my $genopts = shift || die;
10 my $file = $ENV{DAHDI_MODULES_FILE} || "/etc/dahdi/modules";
11 my $self = {
12 FILE => $file,
13 GCONFIG => $gconfig,
14 GENOPTS => $genopts,
15 };
16 bless $self, $pack;
17 return $self;
18 }
19
20 sub generate($$$) {
21 my $self = shift || die;
22 my $file = $self->{FILE};
23 my $gconfig = $self->{GCONFIG};
24 my $genopts = $self->{GENOPTS};
25 rename "$file", "$file.bak"
26 or $! == 2 # ENOENT (No dependency on Errno.pm)
27 or die "Failed to backup old config: $!\n";
28 #$gconfig->dump;
29 print "Generating $file\n" if $genopts->{verbose};
30 open(F, ">$file") || die "$0: Failed to open $file: $!\n";
31 my $old = select F;
32 printf "# Autogenerated by $0 (%s) on %s\n", __PACKAGE__, scalar(localtime);
33 print "# If you edit this file and execute $0 again,\n";
34 print "# your manual changes will be LOST.\n";
35 my @drivers = Dahdi::Hardware->drivers;
36 print join("\n", @drivers),"\n";
37 close F;
38 select $old;
39 }
40
41 1;
42
43 __END__
44
45 =head1 NAME
46
47 modules - Generate list of dahdi drivers to load at startup
48
49 =head1 SYNOPSIS
50
51 use Dahdi::Config::Gen::Dahdi;
52
53 my $cfg = new Dahdi::Config::Gen::Modules(\%global_config, \%genopts);
54 $cfg->generate(@span_list);
55
56 =head1 DESCRIPTION
57
58 Generate the F</etc/dahdi/modules>. This is a list of modules, one per
59 line. This list is normally used by F</etc/init.d/dahdi>.
60
61 Its location may be overriden via the environment variable
62 F<DAHDI_MODULES_FILE>.