From 115d15c04a36dd01af39ae99e0ce9016fbba1551 Mon Sep 17 00:00:00 2001 From: Jacob Pipkin Date: Sun, 4 Nov 2012 08:18:04 -0600 Subject: get_sbo_download - no prototype, keep state, deal with either a single scalar or array passed in, return based on wantarray --- SBO-Lib/lib/SBO/Lib.pm | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'SBO-Lib/lib') 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. -- cgit v1.2.3