]> git.deb.at Git - deb/packages.git/blob - lib/Packages/CGI.pm
b2b261db705b7c009b9cb62c2534b2c3ed4039a7
[deb/packages.git] / lib / Packages / CGI.pm
1 package Packages::CGI;
2
3 use Exporter;
4 our @ISA = qw( Exporter );
5 our @EXPORT = qw( fatal_error error hint debug msg note
6                   print_errors print_hints print_debug print_msgs
7                   print_notes );
8
9 our $debug = 0;
10
11 our (@fatal_errors, @errors, @debug, @msgs, @hints, @notes);
12
13 sub reset {
14     @fatal_errors = @errors = @debug = @msgs = @hints = @notes = ();
15 }
16
17 sub fatal_error {
18     push @fatal_errors, $_[0];
19 }
20 sub error {
21     push @errors, $_[0];
22 }
23 sub hint {
24     push @hints, $_[0];
25 }
26 sub debug {
27     my $lvl = $_[1] || 0;
28     push(@debug, $_[0]) if $debug > $lvl;
29 }
30 sub msg {
31     push @msgs, $_[0];
32 }
33 sub note {
34     push @notes, $_[0];
35 }
36 sub notes {
37     push @notes, [ @_ ];
38 }
39 sub print_errors {
40     return unless @fatal_errors || @errors;
41     print '<div style="background-color:#F99;font-weight:bold;padding:0.5em;margin:0;">';
42     foreach ((@fatal_errors, @errors)) {
43         print "<p>ERROR: $_</p>";
44     }
45     print '</div>';
46 }
47 sub print_debug {
48     return unless $debug && @debug;
49     print '<div style="font-size:80%;border:solid thin grey">';
50     print '<h2>Debugging:</h2><pre>';
51     foreach (@debug) {
52         print "$_\n";
53     }
54     print '</pre></div>';
55 }
56 sub print_hints {
57     return unless @hints;
58     print '<div>';
59     foreach (@hints) {
60         print "<p style=\"background-color:#FF9;padding:0.5em;margin:0\">$_</p>";
61     }
62     print '</div>';
63 }
64 sub print_msgs {
65     foreach (@msgs) {
66         print "<p>$_</p>";
67     }
68 }
69 sub print_notes {
70     foreach (@notes) {
71         my ( $title, $note ) = @$_;
72         my $str = "";
73
74         if ($note) {
75             $str .= "<h2 class=\"pred\">$title</h2>";
76         } else {
77             $note = $title;
78         }
79         $str .= "<p>$note</p>";
80         return $str;
81     }
82 }
83
84 1;