Changeset 405 in ProjectBuilder for devel/pb-modules
- Timestamp:
- Apr 20, 2008, 1:59:47 PM (17 years ago)
- Location:
- devel/pb-modules
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb-modules/Makefile.PL
r403 r405 18 18 EXE_FILES => [ qw( bin/pbdistrocheck ) ], 19 19 MAN3PODS => { 'lib/ProjectBuilder/Distribution.pm' => '$(INST_MAN3DIR)/ProjectBuilder::Distribution.$(MAN3EXT)', 20 'lib/ProjectBuilder/Conf.pm' => '$(INST_MAN3DIR)/ProjectBuilder::Conf.$(MAN3EXT)', 20 21 'lib/ProjectBuilder/Base.pm' => '$(INST_MAN3DIR)/ProjectBuilder::Base.$(MAN3EXT)', }, 21 22 ); -
devel/pb-modules/lib/ProjectBuilder/Base.pm
r402 r405 33 33 34 34 our @ISA = qw(Exporter); 35 our @EXPORT = qw(pb_ conf_read pb_conf_read_if pb_mkdir_p pb_system pb_rm_rf pb_get_date pb_log pb_log_init pb_get_uri pb_get_content pb_display_file pb_syntax_init pb_syntax pb_temp_init $debug $LOG);35 our @EXPORT = qw(pb_mkdir_p pb_system pb_rm_rf pb_get_date pb_log pb_log_init pb_get_uri pb_get_content pb_display_file pb_syntax_init pb_syntax pb_temp_init $debug $LOG); 36 36 37 37 =pod … … 63 63 # 64 64 pb_system("ls -l", "Printing directory content"); 65 66 #67 # Read hash codes of values from a configuration file and return table of pointers68 #69 my ($k1, $k2) = pb_conf_read_if("$ENV{'HOME'}/.pbrc","key1","key2");70 my ($k) = pb_conf_read("$ENV{'HOME'}/.pbrc","key");71 65 72 66 # … … 162 156 } 163 157 164 =item B<pb_conf_read_if>165 166 This function returns a table of pointers on hashes167 corresponding to the keys in a configuration file passed in parameter.168 If that file doesn't exist, it returns undef.169 170 The format of the configuration file is as follows:171 172 key tag = value1,value2,...173 174 Supposing the file is called "$ENV{'HOME'}/.pbrc", containing the following:175 176 $ cat $HOME/.pbrc177 pbver pb = 3178 pbver default = 1179 pblist pb = 12,25180 181 calling it like this:182 183 my ($k1, $k2) = pb_conf_read_if("$ENV{'HOME'}/.pbrc","pbver","pblist");184 185 will allow to get the mapping:186 187 $k1->{'pb'} contains 3188 $ka->{'default'} contains 1189 $k2->{'pb'} contains 12,25190 191 Valid chars for keys and tags are letters, numbers, '-' and '_'.192 193 =cut194 195 sub pb_conf_read_if {196 197 my $conffile = shift;198 my @param = @_;199 200 open(CONF,$conffile) || return((undef));201 close(CONF);202 return(pb_conf_read($conffile,@param));203 }204 205 =item B<pb_conf_read>206 207 This function is similar to B<pb_conf_read_if> except that it dies when the file in parameter doesn't exist.208 209 =cut210 211 sub pb_conf_read {212 213 my $conffile = shift;214 my @param = @_;215 my $trace;216 my @ptr;217 my %h;218 219 open(CONF,$conffile) || die "Unable to open $conffile";220 while(<CONF>) {221 if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {222 pb_log(3,"DEBUG: 1:$1 2:$2 3:$3\n");223 $h{$1}{$2}=$3;224 }225 }226 close(CONF);227 228 for my $param (@param) {229 push @ptr,$h{$param};230 }231 return(@ptr);232 }233 234 158 =item B<pb_get_uri> 235 159
Note:
See TracChangeset
for help on using the changeset viewer.