| 1 | # Copyright Infomation | ||
| 2 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 3 | # Author : Dr. Ahmed Amin Elsheshtawy, Ph.D. | ||
| 4 | # Website: https://github.com/mewsoft/Nile, http://www.mewsoft.com | ||
| 5 | # Email : mewsoft@cpan.org, support@mewsoft.com | ||
| 6 | # Copyrights (c) 2014-2015 Mewsoft Corp. All rights reserved. | ||
| 7 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 8 | package Nile::Abort; | ||
| 9 | |||
| 10 | our $VERSION = '0.55'; | ||
| 11 | our $AUTHORITY = 'cpan:MEWSOFT'; | ||
| 12 | |||
| 13 | =pod | ||
| 14 | |||
| 15 | =encoding utf8 | ||
| 16 | |||
| 17 | =head1 NAME | ||
| 18 | |||
| 19 | Nile::Abort - Abort the application at anytime with optional message and stacktrace. | ||
| 20 | |||
| 21 | =head1 SYNOPSIS | ||
| 22 | |||
| 23 | $self->app->abort("error message"); | ||
| 24 | |||
| 25 | $self->app->abort("error title", "error message"); | ||
| 26 | |||
| 27 | =head1 DESCRIPTION | ||
| 28 | |||
| 29 | Nile::Abort - Abort the application at anytime with optional message and stacktrace. | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | use Nile::Base; | ||
| 34 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 35 | sub abort { | ||
| 36 | |||
| 37 | my ($self) = shift; | ||
| 38 | |||
| 39 | my ($title, $msg, $trace, @trace, $out); | ||
| 40 | |||
| 41 | #my ($callpackage, $callfile, $callline, $subroutine, $hasargs, $wantarray, $evaltext, $is_require) = caller; | ||
| 42 | |||
| 43 | if (@_ == 2) { | ||
| 44 | ($title, $msg) = @_; | ||
| 45 | } | ||
| 46 | else { | ||
| 47 | ($msg) = @_; | ||
| 48 | $title = "Application Error"; | ||
| 49 | } | ||
| 50 | |||
| 51 | #@trace = reverse split(/\n/, Carp::longmess()); | ||
| 52 | #$trace = join ("<br>\n", @trace); | ||
| 53 | #$trace = Carp::longmess(); | ||
| 54 | |||
| 55 | =cuts | ||
| 56 | my $out = <<HTML; | ||
| 57 | <html> | ||
| 58 | <head> | ||
| 59 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
| 60 | <title>Application Error</title> | ||
| 61 | </head> | ||
| 62 | <body style="background: #ffffff;" > | ||
| 63 | |||
| 64 | <div align="center" style="margin-top: 100px;"> | ||
| 65 | <table cellpadding="0" cellspacing="0" style="width: 650px; border: 2px #e5e5e5 solid; border-collapse: collapse;"> | ||
| 66 | <tr><td> | ||
| 67 | <table border="0" cellpadding="8" cellspacing="0" style="border-collapse: collapse" width="100%"> | ||
| 68 | <tr><td style="text-align: center; background: #e5e5e5;"><b>$title</b></td></tr> | ||
| 69 | <tr><td style="background: #f3f3f3;">$msg</td></tr> | ||
| 70 | <tr><td style="background: #f9f9f9;">$trace</td></tr> | ||
| 71 | </table> | ||
| 72 | </td> | ||
| 73 | </tr> | ||
| 74 | </table> | ||
| 75 | </div> | ||
| 76 | </body> | ||
| 77 | </html> | ||
| 78 | HTML | ||
| 79 | =cut | ||
| 80 | |||
| 81 | $out = ""; | ||
| 82 | #$out .= "$title\n\n"; | ||
| 83 | $out .= "$msg\n\n"; | ||
| 84 | #$out .= "$trace\n\n"; | ||
| 85 | |||
| 86 | die $out; | ||
| 87 | #if ($self->app->db->connected) {$self->app->db->disconnect();} | ||
| 88 | } | ||
| 89 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 90 | |||
| 91 | =pod | ||
| 92 | |||
| 93 | =head1 Bugs | ||
| 94 | |||
| 95 | This project is available on github at L<https://github.com/mewsoft/Nile>. | ||
| 96 | |||
| 97 | =head1 HOMEPAGE | ||
| 98 | |||
| 99 | Please visit the project's homepage at L<https://metacpan.org/release/Nile>. | ||
| 100 | |||
| 101 | =head1 SOURCE | ||
| 102 | |||
| 103 | Source repository is at L<https://github.com/mewsoft/Nile>. | ||
| 104 | |||
| 105 | =head1 SEE ALSO | ||
| 106 | |||
| 107 | See L<Nile> for details about the complete framework. | ||
| 108 | |||
| 109 | =head1 AUTHOR | ||
| 110 | |||
| 111 | Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> | ||
| 112 | Website: http://www.mewsoft.com | ||
| 113 | |||
| 114 | =head1 COPYRIGHT AND LICENSE | ||
| 115 | |||
| 116 | Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, | ||
| 117 | L<https://github.com/mewsoft/Nile>, L<http://www.mewsoft.com> | ||
| 118 | |||
| 119 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||
| 120 | |||
| 121 | =cut | ||
| 122 | |||
| 123 | 1; |