Added a test, updated Changes
Devin Austin [Sun, 9 Aug 2009 02:12:18 +0000 (02:12 +0000)]
Changes
t/check_types.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 44250ae..0d0cc77 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,10 @@ This file documents the revision history for Perl extension Catalyst-Devel.
 Moar new stuff - 2009-08-08
          - Began Moosification
          - split into app and component classes
+         - added new Moose types for:
+           - app names
+           - app components
+           - app directory
 
 NOO-STUFFS 2009-06-17
          - added File::ShareDir capabilities
diff --git a/t/check_types.t b/t/check_types.t
new file mode 100644 (file)
index 0000000..5951cd5
--- /dev/null
@@ -0,0 +1,39 @@
+# t0m++
+package My::Types;
+use MooseX::Types -declare [qw/ ValidAppName ValidAppComponent /];
+
+my $appname_re = qr/[\w:]+/;
+my $regex = qr/$appname_re::(M|V|C|Model|View|Controller)::.*/;
+
+subtype ValidAppName, 
+   as Str,
+   where { /^$appname_re$/ && ! /$regex/ };
+
+subtype ValidAppComponent,
+   as Str,
+   where { /^$regex$/ };
+
+coerce ValidAppName,
+   from ValidAppComponent,
+   via { Catalyst::Utils::class2appclass($_); };
+
+package main;
+use Test::More 'no_plan';
+use Moose::Util::TypeContraints;
+use My::Types qw/ValidAppName ValidAppComponent/;
+
+my $app_tc = find_type_constraint(ValidAppName);
+ok $app_tc;
+ok !$app_tc->check('');
+ok $app_tc->check('MyApp');
+
+my $comp_tc = find_type_constraint(ValidAppComponent);
+ok $comp_tc;
+ok !$comp_tc->check('');
+ok !$comp_tc->check('MyApp');
+ok $comp_tc->check('MyApp::Model::Foo');
+
+is $app_tc->coerce('MyApp::Model::Foo'), 'MyApp';
+
+done_testing;
+