Test case using Exception::Class
Ferruccio Zamuner [Tue, 18 Aug 2009 06:55:14 +0000 (06:55 +0000)]
t/dead_test_class_exception.t [new file with mode: 0644]
t/lib/TestAppClassExceptionSimpleTest.pm [new file with mode: 0644]

diff --git a/t/dead_test_class_exception.t b/t/dead_test_class_exception.t
new file mode 100644 (file)
index 0000000..e358043
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use FindBin qw/$Bin/;
+use lib "$Bin/lib";
+use Test::More tests => 1;
+use Test::Exception;
+
+lives_ok {
+    require TestAppClassExceptionSimpleTest;
+} 'Can load application';
+
+1;
+
diff --git a/t/lib/TestAppClassExceptionSimpleTest.pm b/t/lib/TestAppClassExceptionSimpleTest.pm
new file mode 100644 (file)
index 0000000..0c452ce
--- /dev/null
@@ -0,0 +1,85 @@
+package TestAppClassExceptionSimpleTest::Exceptions;
+
+use strict;
+use warnings;
+
+BEGIN {
+    $Catalyst::Exception::CATALYST_EXCEPTION_CLASS = 'TestAppClassExceptionSimpleTest::Exception';
+
+    my %classes = (
+        'TestAppClassExceptionSimpleTest::Exception' => {
+            description => 'Generic exception',
+            alias       => 'throw'
+        },
+    );
+
+    my @exports = grep { defined } map { $classes{ $_ }->{ alias } } keys %classes;
+
+    require Exception::Class;
+    require Sub::Exporter;
+
+    Exception::Class->import(%classes);
+    Sub::Exporter->import( -setup => { exports => \@exports  } );
+}
+
+package TestAppClassExceptionSimpleTest::Exception;
+
+## thank to Brian
+## http://bricas.vox.com/library/post/catalyst-exceptionclass.html
+
+use strict;
+use warnings;
+no warnings 'redefine';
+
+use HTTP::Headers ();
+use HTTP::Status  ();
+use Scalar::Util  qw( blessed );
+
+sub status {
+    return $_[0]->{status} ||= 500;
+}
+
+#########
+
+package TestAppClassExceptionSimpleTest;
+
+use strict;
+use warnings;
+use Scalar::Util ();
+use Catalyst::Runtime '5.80';
+
+use Catalyst qw/ -Debug /;
+
+our $VERSION = '0.02';
+
+# Start the application
+__PACKAGE__->setup;
+
+=head1 NAME
+
+TestAppClassExceptionSimpleTest - Catalyst based application
+
+=head1 SYNOPSIS
+
+    script/TestAppClassExceptionSipleTest_server.pl
+
+=head1 DESCRIPTION
+
+[enter your description here]
+
+=head1 SEE ALSO
+
+L<TestAppClassException::Controller::Root>, L<Catalyst>
+
+=head1 AUTHOR
+
+Ferruccio Zamuner
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;