]> git.p6c8.net - devedit.git/blob - modules/Output.pm
This file testing order before saving a file makes more sense
[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: 2004-11-26
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. Display a link to this path at the bottom of the page (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("BACK",$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. Display a link to this path at the bottom of the page (optional)
88 # 3. Hash reference: Template variables (optional)
89
90 sub abort($;$$)
91 {
92 my $output = error(shift,shift,shift);
93 print $$output;
94 exit;
95 }
96
97 # it's true, baby ;-)
98
99 1;
100
101 #
102 ### End ###

patrick-canterino.de