MegaDistro/Config.pm untested

filter: Statementstmt 0.0% 0 / 108 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 190 CC 11 SCAR 32.6
CC
11
Cov
0%
pre
72.0
init_config
12.0
build_tree
6.0
CRAP 25.9
1 package MegaDistro::Config;
2  
3 use strict;
4 use warnings;
5  
6 use Exporter;
7 our @ISA = qw(Exporter);
8 our @EXPORT = qw(%args %Conf);
9 our @EXPORT_OK = qw(pre push_libs build_clean help $DEVNULL);
10 our %EXPORT_TAGS;
11 $EXPORT_TAGS{'default'} = \@EXPORT;
12  
13 use File::Path;
14 use File::Spec::Functions qw(:ALL);
15  
16  
17 # Hash containing the various directories to be used by the system
18 our %Conf;
19  
20 # Hash containing the various command-line arguements, passed to the program,
21 our %args;
22  
23 sub init_config {
24 my %overrides = @_;
25  
26 %Conf = %overrides;
27  
28 $Conf{'homedir'} ||= $ENV{HOME};
29  
30 $Conf{'rootdir'} ||= catdir($Conf{'homedir'}, '.megadistro');
31  
32 $Conf{'fetchdir'} ||= catdir($Conf{'rootdir'}, 'Fetch');
33 $Conf{'extractdir'} ||= catdir($Conf{'rootdir'}, 'Extract');
34 $Conf{'builddir'} ||= catdir($Conf{'rootdir'}, 'Build');
35  
36 # do not change!
37 # (used to adjust path, when makemakerflags
38 # uses PREFIX instead of DESTDIR).
39 $Conf{'prefixdir'} ||= catdir($Conf{'builddir'}, 'usr');
40
41 # Configurable Files used in building the package
42  
43 $Conf{'modlist'} ||= catfile($Conf{'rootdir'}, "modules.list");
44  
45 # Make everything absolute in case we chdir.
46 for my $key (grep !/^disttype$/, keys %Conf) {
47 $Conf{$key} = rel2abs($Conf{$key});
48 }
49  
50 if ( $Conf{disttype} && $Conf{disttype} !~ /^(rpm|deb)/i ) {
51 die "Invalid package type! - Valid types are: rpm , deb" . "\n";
52 }
53  
54 # HACK: Let the other config modules see our changes.
55 require MegaDistro::RpmMaker::Config;
56 require MegaDistro::DebMaker::Config;
57 MegaDistro::RpmMaker::Config::_init_globals();
58 MegaDistro::DebMaker::Config::_init_globals();
59  
60 for my $key (keys %Conf) {
61 print "$key: $Conf{$key}\n" if $args{debug};
62 }
63 }
64 init_config();
65  
66  
67 #
68 # Other random configurables
69 #
70 # /dev/null
71 our $DEVNULL = '/dev/null 2>&1';
72  
73 #
74 # Preparation
75 #
76 sub pre {
77 if ( $args{'trace'} ) {
78 print 'MegaDistro::Config : Executing sub-routine: pre' . "\n";
79 }
80
81 if ( ! -d "$Conf{'fetchdir'}" ) {
82 if ( $args{'debug'} ) {
83 print "\t" . 'Fetch directory: ' . $Conf{'fetchdir'} . ' does not exist, creating it' . "\n";
84 }
85 mkpath $Conf{'fetchdir'};
86 }
87 if ( ! -d "$Conf{'extractdir'}" ) {
88 if ( $args{'debug'} ) {
89 print "\t" . 'Extract directory: ' . $Conf{'extractdir'} . ' does not exist, creating it' . "\n";
90 }
91 mkpath $Conf{'extractdir'};
92 }
93 if ( ! -d "$Conf{'builddir'}" ) {
94 if ( $args{'debug'} ) {
95 print "\t" . 'Build directory: ' . $Conf{'builddir'} . ' does not exist, creating it' . "\n";
96 }
97 mkpath $Conf{'builddir'};
98 }
99
100 &build_tree;
101 }
102  
103 use Config;
104  
105 sub prop_libs {
106 my @add_libs;
107 push @add_libs, catdir($Conf{'builddir'}, $Config{'installarchlib'});
108 push @add_libs, catdir($Conf{'builddir'}, $Config{'installvendorarch'});
109 push @add_libs, catdir($Conf{'builddir'}, $Config{'installvendorlib'});
110 return @add_libs;
111 }
112  
113 sub push_libs {
114 my @add_libs = &prop_libs;
115 for (@add_libs) { #optional reverse.
116 unshift @INC, $_;
117 }
118 }
119  
120 sub build_tree {
121 my @build_libs = &prop_libs;
122 for (@build_libs) {
123 mkpath $_ if ! -d "$_";
124 }
125 }
126  
127 sub build_clean {
128  
129 rmtree "$Conf{'builddir'}/*";
130  
131 }
132  
133 sub help { #perhaps replace with <<
134 print "\n";
135 print "Usage: Configure [OPTION]... [--disttype=TYPE]" . "\n";
136 print " or: Configure [-q] [-dxv] [-t TYPE]" . "\n";
137 print " or: Configure [-h]" . "\n";
138 print "Run the Configure system, and specify package type." . "\n";
139 print "\n";
140 print "The following arguements are all optional," . "\n";
141 print " however you should always specify the package type." . "\n";
142 print "\n";
143 print " -h, --help displays this help information" . "\n";
144 print " -t TYPE, --disttype=TYPE package type to build - " . "\n";
145 print " valid types are 'deb' and 'rpm'" . "\n";
146 print " -v, --verbose verbose output" . "\n";
147 print " (not recommended)" . "\n";
148 print " -d, --debug debbuging output" . "\n";
149 print " (for development only)" . "\n";
150 print " -q, --quiet only display status information" . "\n";
151 print " (obsolete)" . "\n";
152 print " -x, --trace trace the program execution" . "\n";
153 print " (for development only)" . "\n";
154 print " --clean completely removes everything" . "\n";
155 print " from BUILDDIR" . "\n";
156 print " --force forces the install of all modules" . "\n";
157 print " (use carefully!)" . "\n";
158 print " --build-only skips the packaging phase," . "\n";
159 print " builds snapshot of build-tree" . "\n";
160 print " --modlist=FILE set the module list to use" . "\n";
161 print " --fetchdir=DIR set directory to download modules" . "\n";
162 print " --extractdir=DIR set directory to extract modules" . "\n";
163 print " --builddir=DIR set directory for built modules" . "\n";
164 print "\n";
165 }
166  
167 1;