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

patrick-canterino.de