Deprecate bare imports of Catalyst::Test - either use an app name or don't run the...
Tomas Doran [Mon, 11 Jan 2010 21:11:05 +0000 (21:11 +0000)]
Changes
lib/Catalyst/Test.pm
t/aggregate/deprecated_test_import.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 1be1533..176d54d 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,11 @@
   Documentation:
    - Clarify that uri_for_action works on private paths, with example.
 
+  Deprecations:
+   - Saying use Catalyst::Test; (without an application name or () to stop
+     the importer running is now deprecated and will issue a warning.
+     You should be saying use Catalyst::Test ();
+
 5.80017 2010-01-10 02:27:29
 
   Documentation:
index 8776803..f987172 100644 (file)
@@ -103,6 +103,12 @@ our $default_host;
 
     sub import {
         my ($self, $class, $opts) = @_;
+        Carp::carp(
+qq{Importing Catalyst::Test without an application name is deprecated:\n
+Instead of saying: use Catalyst::Test;
+say: use Catalyst::Test (); # If you don't want to import a test app right now.
+or say: use Catalyst::Test 'MyApp'; # If you do want to import a test app.\n\n})
+        unless $class;
         $import->($self, '-all' => { class => $class });
         $opts = {} unless ref $opts eq 'HASH';
         $default_host = $opts->{default_host} if exists $opts->{default_host};
diff --git a/t/aggregate/deprecated_test_import.t b/t/aggregate/deprecated_test_import.t
new file mode 100644 (file)
index 0000000..ee90eea
--- /dev/null
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Catalyst::Test ();
+
+my $warn;
+{
+    local $SIG{__WARN__} = sub { $warn = shift; };
+    Catalyst::Test->import();
+}
+ok $warn;
+like $warn, qr/deprecated/;
+
+done_testing;
+