diff options
| author | Jacob Pipkin <j@dawnrazor.net> | 2012-11-04 08:18:04 -0600 | 
|---|---|---|
| committer | Jacob Pipkin <j@dawnrazor.net> | 2012-11-04 08:18:04 -0600 | 
| commit | 115d15c04a36dd01af39ae99e0ce9016fbba1551 (patch) | |
| tree | 6d6b75ac5295685aa30d75800365c133ae73b31d /SBO-Lib/lib/SBO | |
| parent | 3ee3882b89ea051a0851edf369fd8adafa2944d2 (diff) | |
| download | sbotools2-115d15c04a36dd01af39ae99e0ce9016fbba1551.tar.xz | |
get_sbo_download - no prototype, keep state, deal with either a single scalar or array passed in, return based on wantarray
Diffstat (limited to 'SBO-Lib/lib/SBO')
| -rw-r--r-- | SBO-Lib/lib/SBO/Lib.pm | 26 | 
1 files changed, 19 insertions, 7 deletions
| diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm index e9f10d9..21f62c6 100644 --- a/SBO-Lib/lib/SBO/Lib.pm +++ b/SBO-Lib/lib/SBO/Lib.pm @@ -219,17 +219,29 @@ sub get_inst_names ($) {  }  # search the SLACKBUILDS.TXT for a given sbo's directory -sub get_sbo_location ($) { +sub get_sbo_location {  	exists $_[0] or script_error 'get_sbo_location requires an argument.'; -	my $sbo = shift; -	my $regex = qr#LOCATION:\s+\.(/[^/]+/\Q$sbo\E)$#; +	my @sbos = @_; +	state $loc_store = {}; +	# if scalar context and we've already have the location, return it now. +	unless (wantarray) { +		return $loc_store{$sbos[0]} if exists $loc_store{$sbos[0]}; +	} +	my %locations;  	my $fh = open_read $slackbuilds_txt; -	while (my $line = <$fh>) { -		if (my $loc = ($line =~ $regex)[0]) { -			return "$config{SBO_HOME}$loc"; +	for my $sbo (@$sbos) { +		my $regex = qr#LOCATION:\s+\.(/[^/]+/\Q$sbo\E)$#; +		while (my $line = <$fh>) { +			if (my $loc = ($line =~ $regex)[0]) { +				$loc_store{$sbo} = "$config{SBO_HOME}$loc"; +				return $loc_store{$sbo} unless wantarray; +				$locations{$sbo} = $loc_store{$sbo}; +			}  		} +		seek $fh, 0, 0;  	} -	return; +	close $fh; +	return %locations;  }  # pull the sbo name from a $location: $config{SBO_HOME}/system/wine, etc. | 
