[Catalyst-commits] r11066 - in
Catalyst-Devel/1.00/branches/moosify_api: . t
dhoss at dev.catalyst.perl.org
dhoss at dev.catalyst.perl.org
Sun Aug 9 02:12:19 GMT 2009
Author: dhoss
Date: 2009-08-09 02:12:18 +0000 (Sun, 09 Aug 2009)
New Revision: 11066
Added:
Catalyst-Devel/1.00/branches/moosify_api/t/check_types.t
Modified:
Catalyst-Devel/1.00/branches/moosify_api/Changes
Log:
Added a test, updated Changes
Modified: Catalyst-Devel/1.00/branches/moosify_api/Changes
===================================================================
--- Catalyst-Devel/1.00/branches/moosify_api/Changes 2009-08-09 01:03:12 UTC (rev 11065)
+++ Catalyst-Devel/1.00/branches/moosify_api/Changes 2009-08-09 02:12:18 UTC (rev 11066)
@@ -3,6 +3,10 @@
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
Added: Catalyst-Devel/1.00/branches/moosify_api/t/check_types.t
===================================================================
--- Catalyst-Devel/1.00/branches/moosify_api/t/check_types.t (rev 0)
+++ Catalyst-Devel/1.00/branches/moosify_api/t/check_types.t 2009-08-09 02:12:18 UTC (rev 11066)
@@ -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;
+
More information about the Catalyst-commits
mailing list