From: Tomas Doran Date: Tue, 9 Feb 2010 01:13:15 +0000 (+0000) Subject: Add a nice loud warning for idiots like me who type the wrong thing all the time X-Git-Tag: 0.001003~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Types-Common.git;a=commitdiff_plain;h=acf4d2451ea67988eda7857ad537abe53f0fec62 Add a nice loud warning for idiots like me who type the wrong thing all the time --- diff --git a/Changes b/Changes index 8bb7417..4cc5cb3 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,6 @@ + - Warning when you try to import things from MooseX::Types::Common rather + than one of the specific String/Numeric modules in the distribution. 0.001001 2010-01-04 - POD updates 0.001000 - - Initial release. This is a spin off from Reaction. \ No newline at end of file + - Initial release. This is a spin off from Reaction. diff --git a/lib/MooseX/Types/Common.pm b/lib/MooseX/Types/Common.pm index 63b206f..49341bd 100644 --- a/lib/MooseX/Types/Common.pm +++ b/lib/MooseX/Types/Common.pm @@ -2,9 +2,18 @@ package MooseX::Types::Common; use strict; use warnings; +use Carp qw/cluck/; our $VERSION = '0.001001'; +sub import { + my $package = shift; + return unless @_; + cluck("Tried to import the symbols " . join(', ', @_) + . " from MooseX::Types::Common.\nDid you mean " + . "MooseX::Types::Common::String or MooseX::Type::Common::Numeric?"); +} + 1; =head1 NAME diff --git a/t/03-idiot.t b/t/03-idiot.t new file mode 100644 index 0000000..20c0f2b --- /dev/null +++ b/t/03-idiot.t @@ -0,0 +1,28 @@ +use strict; +use warnings; + +use Test::More; + +# Test for a warning when you make the stupid mistake I make all the time +# of saying use MooseX::Types::Common qw/NonEmptySimpleStr/; + +BEGIN { + eval { require Capture::Tiny } + or plan skip_all => 'Capture::Tiny needed for these tests'; +} + +plan tests => 4; + +use_ok 'MooseX::Types::Common'; + +my ($stdout, $stderr) = Capture::Tiny::capture(sub { + MooseX::Types::Common->import; +}); +is $stderr, '', 'No warning if nothing imported'; + +($stdout, $stderr) = Capture::Tiny::capture(sub { + MooseX::Types::Common->import('NonEmptySimpleStr'); +}); +like $stderr, qr/Did you mean/, 'Got warning'; +like $stderr, qr/NonEmptySimpleStr/, 'Warning mentions bad type'; +