X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=lib%2FPackages%2FCGI.pm;h=9a8584fe6bd51b4cf784ad1dc37d522215ab4e33;hb=2ec757bb58907b15c43548be5601d4f2b8c7caac;hp=0dded210ef0be99c43428de70fbf7444c217a41d;hpb=6af10f3657d5ef5e0d15fe4a48590655fe136b7b;p=deb%2Fpackages.git diff --git a/lib/Packages/CGI.pm b/lib/Packages/CGI.pm index 0dded21..9a8584f 100644 --- a/lib/Packages/CGI.pm +++ b/lib/Packages/CGI.pm @@ -7,9 +7,10 @@ use Exporter; use Packages::Config; our @ISA = qw( Exporter ); -our @EXPORT = qw( fatal_error error hint debug msg note - print_errors print_hints print_debug print_msgs - print_notes DEBUG make_url make_search_url ); +our @EXPORT = qw( DEBUG debug fatal_error ); +our @EXPORT_OK = qw( error hint msg note get_all_messages + make_url make_search_url ); + # define this to 0 in production mode use constant DEBUG => 1; @@ -40,50 +41,22 @@ sub msg { sub note { push @notes, [ @_ ]; } -sub print_errors { - return unless @fatal_errors || @errors; - print '
'; - foreach ((@fatal_errors, @errors)) { - print "

ERROR: $_

"; - } - print '
'; -} -sub print_debug { +sub get_errors { (@fatal_errors, @errors) } +sub get_debug { return unless $debug && @debug; - print '
'; - print '

Debugging:

';
-    foreach (@debug) {
-	print "$_\n";
-    }
-    print '
'; + return @debug; } -sub print_hints { - return unless @hints; - print '
'; - foreach (@hints) { - print "

$_

"; - } - print '
'; -} -sub print_msgs { - print '
'; - foreach (@msgs) { - print "

$_

"; - } - print '
'; -} -sub print_notes { - foreach (@notes) { - my ( $title, $note ) = @$_; - - print '
'; - if ($note) { - print "

$title

"; - } else { - $note = $title; - } - print "

$note

"; - } +sub get_msgs { @msgs }; +sub get_hints { @hints }; +sub get_notes { @notes }; +sub get_all_messages { + return { + errors => [ @fatal_errors, @errors ], + debugs => $debug ? \@debug : [], + msgs => \@msgs, + hints => \@hints, + notes => \@notes, + }; } our $USE_PAGED_MODE = 1; @@ -400,9 +373,14 @@ sub init_url { } sub make_url { - my ($add_path, $add_query, $override) = @_; + my ($add_path, $add_query, @override) = @_; my (@path, @query_string) = ()x2; - $override ||= {}; + my $override = {}; + if (ref $override[0]) { + $override = $override[0]; + } elsif (@override) { + $override = { @override }; + } push @path, $Packages::Config::ROOT; foreach my $p (qw(lang source suite archive arch)) { @@ -428,9 +406,14 @@ sub make_url { } sub make_search_url { - my ($add_path, $add_query, $override) = @_; + my ($add_path, $add_query, @override) = @_; my (@path, @query_string) = ()x2; - $override ||= {}; + my $override ||= {}; + if (ref $override[0]) { + $override = $override[0]; + } elsif (@override) { + $override = { @override }; + } push @path, $Packages::Config::SEARCH_URL if $Packages::Config::SEARCH_URL; @@ -445,7 +428,7 @@ sub make_search_url { push @query_string, $add_query if $add_query; my $path = join( '/', @path ); - my $query_string = join( '&', @query_string ); + my $query_string = join( '&', @query_string ); return "$path?$query_string"; }