]> git.deb.at Git - deb/packages.git/blob - lib/Packages/CGI.pm
* complete virtual package support
[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, [ @_ ];
35 }
36 sub print_errors {
37     return unless @fatal_errors || @errors;
38     print '<div style="background-color:#F99;font-weight:bold;padding:0.5em;margin:0;">';
39     foreach ((@fatal_errors, @errors)) {
40         print "<p>ERROR: $_</p>";
41     }
42     print '</div>';
43 }
44 sub print_debug {
45     return unless $debug && @debug;
46     print '<div style="font-size:80%;border:solid thin grey">';
47     print '<h2>Debugging:</h2><pre>';
48     foreach (@debug) {
49         print "$_\n";
50     }
51     print '</pre></div>';
52 }
53 sub print_hints {
54     return unless @hints;
55     print '<div>';
56     foreach (@hints) {
57         print "<p style=\"background-color:#FF9;padding:0.5em;margin:0\">$_</p>";
58     }
59     print '</div>';
60 }
61 sub print_msgs {
62     foreach (@msgs) {
63         print "<p>$_</p>";
64     }
65 }
66 sub print_notes {
67     foreach (@notes) {
68         my ( $title, $note ) = @$_;
69
70         print '<div style="border: solid thin black; background-color: #ccf">';
71         if ($note) {
72             print "<h2 class=\"pred\">$title</h2>";
73         } else {
74             $note = $title;
75         }
76         print "<p>$note</p></div>";
77     }
78 }
79
80 1;