X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=lib%2FPackages%2FCGI.pm;h=c29e56ce8b932014b562c56e33c68d6f4c8181c9;hb=5eefedd1fae821a3981218ceaccb7f5e50f823f9;hp=236dd8df3b1e976341af46b8ba91d06f14473dc1;hpb=7a35406ba508365d2a25bd77c6ae8599807bdd1c;p=deb%2Fpackages.git diff --git a/lib/Packages/CGI.pm b/lib/Packages/CGI.pm index 236dd8d..c29e56c 100644 --- a/lib/Packages/CGI.pm +++ b/lib/Packages/CGI.pm @@ -4,25 +4,39 @@ use strict; use warnings; 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 get_mime ); +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; our $debug = 0; -our (@fatal_errors, @errors, @debug, @msgs, @hints, @notes); +my %mime_types = ( + txt => 'text/plain', + 'txt.gz' => 'text/plain', + html => 'text/html', + rss => 'application/rss+xml', + rfc822 => 'text/plain', + ); + +sub get_mime { + return $mime_types{$_[0]} || $_[1] || 'text/html'; +} + +our (@fatal_errors, @errors, @debug, @hints); +our $http_code; sub reset { - @fatal_errors = @errors = @debug = @msgs = @hints = @notes = (); + @fatal_errors = @errors = @debug = @hints = (); + $http_code = 200; } sub fatal_error { push @fatal_errors, $_[0]; + $http_code = $_[1] if $_[1]; } sub error { push @errors, $_[0]; @@ -34,56 +48,18 @@ sub debug { my $lvl = $_[1] || 0; push(@debug, $_[0]) if $debug > $lvl; } -sub msg { - push @msgs, $_[0]; -} -sub note { - push @notes, [ @_ ]; -} -sub print_errors { - return unless @fatal_errors || @errors; - print '
ERROR: $_
"; - } - print ''; - foreach (@debug) { - print "$_\n"; - } - print '
$_
"; - } - print '$_
"; - } - print '$note