9 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use strict;
BEGIN {
package Error;
my @ErrorDefinitions = qw/
LOGINFAILED
/;
for my $i (0 .. $#ErrorDefinitions) {
eval "use constant $ErrorDefinitions[$i] => '$ErrorDefinitions[$i]';";
}
1;
}
package Error;
my %RaisedErrors = ();
sub raise {
my ($errid, $errmsg) = @_;
exists $RaisedErrors->{$errid} || $RaisedErrors->{$errid} = [];
push @{$RaisedErrors->{$errid}}, {MSG => $errmsg} if $errmsg;
}
sub to_html_template {
my ($tpl) = @_;
while(my($key, $val) = each %RaisedErrors) {
$tpl->param("ERROR_$key" => 1);
$tpl->param("ERROR_$key_msg" => $val;
}
}
1;
1
2
3
4
5
6
7
8
9
10
use Error;
my $tpl = ...; # HTML::Template
if($login_failed) {
Error::raise(Error::LOGINFAILED, "Falsches Passwort");
}
Error::to_html_template($tpl);
print $tpl->output;
1
2
3
4
5
6
7
8
9
10
<html>
<body>
<TMPL_IF NAME=ERROR_LOGINFAILED>
Login ist fehlgeschlagen<br />
<TMPL_LOOP NAME=ERROR_LOGINFAILED_MSG>
<TMPL_VAR NAME=MSG><br />
</TMPL_LOOP>
</TMPL_IF>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/perl
use strict;
use warnings;
use lib qw(../modules);
use CGI::Carp qw/fatalsToBrowser warningsToBrowser set_message/;
use CGI;
use HTML::Template;
use MyCMS;
my $maintemplate = '../tmpl/main.html';
sub handle_error {
my $msg = shift;
my $tmpl = HTML::Template->new(filename => $maintemplate);
$tmpl->param(TITLE => 'Serverfehler');
$tmpl->param(INHALT => "<h2>Serverfehler</h2>
<p>Bitte Kontaktieren sie webmaster\@creedforever.com mit folgender Fehlermeldung:</p>
<tt>$msg</tt>");
print $tmpl->output();
}
set_message(\&handle_error);
...
$c->stash->{error} = 'Da is was schiefgelaufen';
9 Einträge, 1 Seite |