5 use List
::Util qw
/max/;
7 my ($error_code) = CGI
->new->param('code');
10 if( $error_code == 404 ) {
13 if( $ENV{HTTP_REFERER
}
14 && $ENV{HTTP_REFERER
} =~ m
|http
://[^/]*$ENV{HTTP_HOST
}|
15 && $c->get_conf('production_server')
18 # this 404 is our mistake (i.e. the referrer is one of ours),
19 # try to send the dev team an email before displaying the 404
22 require Mail
::Sendmail
;
24 my $script_name = $ENV{HTTP_REFERER
};
25 $script_name =~ s
|.+\
/||;
26 Mail
::Sendmail
::sendmail
(
27 To
=> $c->get_conf('bugs_email'),
28 From
=> 'www@'.$ENV{HTTP_HOST
},
29 Subject
=> "Broken link on $script_name: $ENV{REQUEST_URI}",
30 Body
=> "Broken link $ENV{REQUEST_URI} on page $ENV{HTTP_REFERER}.\n\nEnvironment:\n".format_env
( %ENV ),
31 ) or die $Mail::Sendmail
::error
;
33 warn "$0: could not send 404 broken link email: $_";
36 $c->forward_to_mason_view( '/site/error/404.mas', message
=> 'We apologize for the inconvenience. An error report has been sent to the development team.' );
38 $c->forward_to_mason_view( '/site/error/404.mas', message
=> 'You may want to contact the referring site and inform them of this error.');
43 $c->forward_to_mason_view( '/site/error/'.($error_code+0).'.mas' );
46 # format the ENV hash into name => value, one per line,
47 # with names padded to make the output columnar
50 my $key_width = 3 + max
map length, keys %env;
53 . ' ' x
( $key_width - length ) # padding