From 39254b72d35472ffc1fa1adbd56e516885d8dd70 Mon Sep 17 00:00:00 2001 From: "A. Gordon" Date: Thu, 26 Jul 2012 12:24:24 -0400 Subject: [PATCH] Example: Dancer's error handling. --- lib/dancer_bootstrap_fontawesome_template.pm | 1 + lib/examples/error_handling.pm | 30 +++++++ views/examples/error_handling.tt | 94 ++++++++++++++++++++ views/index.tt | 1 + 4 files changed, 126 insertions(+) create mode 100644 lib/examples/error_handling.pm create mode 100644 views/examples/error_handling.tt diff --git a/lib/dancer_bootstrap_fontawesome_template.pm b/lib/dancer_bootstrap_fontawesome_template.pm index de29839..a64aa52 100644 --- a/lib/dancer_bootstrap_fontawesome_template.pm +++ b/lib/dancer_bootstrap_fontawesome_template.pm @@ -11,6 +11,7 @@ use examples::show_file; use examples::photo_gallery; use examples::markdown; use examples::template_plugins; +use examples::error_handling; our $VERSION = '0.1'; diff --git a/lib/examples/error_handling.pm b/lib/examples/error_handling.pm new file mode 100644 index 0000000..b63b990 --- /dev/null +++ b/lib/examples/error_handling.pm @@ -0,0 +1,30 @@ +package examples::error_handling; +use Dancer ':syntax'; +use strict; +use warnings; + +=pod +This module demonstrates Dancer's error handling capabilities, in development and production modes. + +=cut + +get '/error_handling' => sub { + template 'examples/error_handling'; +}; + +post '/error_handling' => sub { + my $show_errors = param 'showerrors'; + print STDERR "show_errors = $show_errors\n"; + $show_errors = 1 unless $show_errors eq "0"; + +=pod +NOTE: + In a real project, you should never set "show_errors" like this. + Set it properly in both "./environments/development.yml" and + ./environments/production.yml" . +=cut + set show_errors => $show_errors; + die "Oops, I did it again"; +}; + +true; diff --git a/views/examples/error_handling.tt b/views/examples/error_handling.tt new file mode 100644 index 0000000..298521a --- /dev/null +++ b/views/examples/error_handling.tt @@ -0,0 +1,94 @@ +[%### +This page demonstrates Dancer's stack-trace error handling in development mode. +###%] + + + + + +
+ + + +
+
+ + This page demonstrates Dancer's error handling code, in development and production modes. +
+ In development mode, any die statement will generate a detailed stack-trace with loads of information. In production mode, die statements will generate a generic error message. +
+
+ +

Code Highlights

+ + +
+
+ +
+
+ +
+
+[%################################ + Error Handling Example starts here +#################################%] + +
+
+ Error Handling Example + +
+By clicking on the button below, you will get a Runtime error message - it's not a bug - it's the whole point of this demonstration. +
+ + +
+ +
+ + +
+
+ + + +
+ +
+
+
+ +
+
diff --git a/views/index.tt b/views/index.tt index 67d0841..c6d2dbf 100644 --- a/views/index.tt +++ b/views/index.tt @@ -92,6 +92,7 @@
  • Photo Gallery Grid / Thumbnails
  • Markdown Text Rendering
  • Template::Toolkit plugins
  • +
  • Dancer's Error Handling