]> git.p6c8.net - devedit.git/blob - modules/Output.pm
- Added some notes for changing mode and group
[devedit.git] / modules / Output.pm
1 package Output;
2
3 #
4 # Dev-Editor - Module Output
5 #
6 # HTML generating routines
7 #
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 2004-03-12
10 #
11
12 use strict;
13
14 use vars qw(@EXPORT);
15
16 use CGI qw(header);
17 use Tool;
18
19 use HTML::Entities;
20 use Template;
21
22 ### Export ###
23
24 use base qw(Exporter);
25
26 @EXPORT = qw(error_template
27 error
28 abort);
29
30 my $tpl_error;
31
32 # error_template()
33 #
34 # Set the path to the template file used for error messages
35 # (I'm lazy...)
36 #
37 # Params: Template file
38
39 sub error_template($)
40 {
41 $tpl_error = shift;
42 }
43
44 # error()
45 #
46 # Format an error message
47 #
48 # Params: 1. Error message
49 # 2. Virtual path to which a link should be displayed (optional)
50 # 3. Hash reference: Template variables (optional)
51 #
52 # Return: Formatted message (Scalar Reference)
53
54 sub error($;$$)
55 {
56 my ($message,$path,$vars) = @_;
57
58 my $tpl = new Template;
59 $tpl->read_file($tpl_error);
60
61 $tpl->fillin("ERROR",$message);
62 $tpl->fillin("DIR",$path);
63 $tpl->fillin("SCRIPT",encode_entities($ENV{'SCRIPT_NAME'}));
64
65 $tpl->parse_if_block("dir",defined $path);
66
67 if(ref($vars) eq "HASH")
68 {
69 while(my ($key,$value) = each(%$vars))
70 {
71 $tpl->fillin($key,$value);
72 }
73 }
74
75 my $output = header(-type => "text/html");
76 $output .= $tpl->get_template;
77
78 return \$output;
79 }
80
81 # abort()
82 #
83 # Print an error message and exit script
84 # ^^^^^
85 #
86 # Params: 1. Error message
87 # 2. Hash reference: Template variables (optional)
88
89 sub abort($;$)
90 {
91 my $output = error(shift,undef,shift);
92 print $$output;
93 exit;
94 }
95
96 # it's true, baby ;-)
97
98 1;
99
100 #
101 ### End ###

patrick-canterino.de