blib/lib/ASP4/ErrorHandler/Remote.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 60 CC 1 SCAR 6.9
CC
1
Cov
0%
run
2.0
send_error
2.0
BEGIN
2.0
CRAP 2.0
1  
2 package ASP4::ErrorHandler::Remote;
3  
4 use strict;
5 use warnings 'all';
6 use base 'ASP4::ErrorHandler';
7 use vars __PACKAGE__->VARS;
8 use LWP::UserAgent;
9 use HTTP::Request::Common;
10 use HTTP::Date 'time2iso';
11 use JSON::XS;
12 use Data::Dumper;
13 require ASP4;
14  
15 our $ua;
16  
17 sub run
18 {
19 my ($s, $context) = @_;
20
21 my $error = $Stash->{error};
22
23 $s->print_error( $error );
24 $s->send_error($error);
25 }# end run()
26  
27  
28 sub send_error
29 {
30 my ($s, $error) = @_;
31
32 $ua ||= LWP::UserAgent->new();
33 $ua->agent( ref($s) . " $ASP4::VERSION" );
34 my %clone = %$error;
35 my $req = POST $Config->errors->post_errors_to, \%clone;
36 $ua->request( $req );
37 }# end send_error()
38  
39 1;# return true:
40  
41 =pod
42  
43 =head1 NAME
44  
45 ASP4::ErrorHandler::Remote - Send your errors someplace else via http.
46  
47 =head1 SYNOPSIS
48  
49 In your C<asp4-config.json>:
50  
51 ...
52 "errors": {
53 "error_handler": "ASP4::ErrorHandler::Remote",
54 "post_errors_to": "http://errors.ohno.com/post/errors/here/"
55 },
56 ...
57  
58 =head1 DESCRIPTION
59  
60 This class provides a default error handler which does the following:
61  
62 1) Makes a simple HTML page and prints it to the browser, telling the user
63 that an error has just occurred.
64  
65 2) Sends an error notification to the web address specified in the config.
66  
67 The data contained within the POST will match the public properties of L<ASP4::Error>, like this:
68  
69 $VAR1 = {
70 'remote_addr' => '127.0.0.1',
71 'request_uri' => '/',
72 'user_agent' => 'test-useragent v2.0',
73 'file' => '/home/john/Projects/myapp/www/htdocs/index.asp',
74 'session_data' => '{}',
75 'message' => 'A fake error has occurred',
76 'http_code' => '500',
77 'stacktrace' => 'A fake error has occurred at /tmp/PAGE_CACHE/TSR_WWW/__index_asp.pm line 2.
78 ',
79 'domain' => 'www.tsr.local',
80 'form_data' => '{}',
81 'http_referer' => '',
82 'code' => 'line 1: <h1>Hello, world!</h1>
83 line 2: <%
84 line 3: die "A fake error has occurred";
85 line 4: %>
86 ',
87 'line' => '2'
88 };
89  
90  
91 =head1 PUBLIC METHODS
92  
93 =head2 send_error( $error )
94  
95 Sends the error data to the web address specified in C<<$Config->errors->post_errors_to>>.
96  
97 The field names and values will correspond to the properties of an C<ASP4::Error> object.
98  
99 =head1 BUGS
100  
101 It's possible that some bugs have found their way into this release.
102  
103 Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ASP4> to submit bug reports.
104  
105 =head1 HOMEPAGE
106  
107 Please visit the ASP4 homepage at L<http://0x31337.org/code/> to see examples
108 of ASP4 in action.
109  
110 =head1 AUTHOR
111  
112 John Drago <jdrago_999@yahoo.com>
113  
114 =head1 COPYRIGHT
115  
116 Copyright 2008 John Drago. All rights reserved.
117  
118 =head1 LICENSE
119  
120 This software is Free software and is licensed under the same terms as perl itself.
121  
122 =cut
123