need to move the marked lines into one method
[catagits/Catalyst-Devel.git] / t / check_types.t
CommitLineData
12594914 1# t0m++
2package My::Types;
3use MooseX::Types -declare [qw/ ValidAppName ValidAppComponent /];
4
5my $appname_re = qr/[\w:]+/;
6my $regex = qr/$appname_re::(M|V|C|Model|View|Controller)::.*/;
7
8subtype ValidAppName,
9 as Str,
10 where { /^$appname_re$/ && ! /$regex/ };
11
12subtype ValidAppComponent,
13 as Str,
14 where { /^$regex$/ };
15
8dccaa92 16subtype AppEnv,
17 as Str,
18 where { /\w/ };
19
12594914 20coerce ValidAppName,
21 from ValidAppComponent,
22 via { Catalyst::Utils::class2appclass($_); };
8dccaa92 23
24coerce 'ValidAppEnv',
25 from Str,
26 via { Catalyst::Utils::class2env($_); };
27
28coerce AppEnv,
29 from Str,
30 via { Catalyst::Utils::class2env($_) };
12594914 31
32package main;
33use Test::More 'no_plan';
34use Moose::Util::TypeContraints;
8dccaa92 35use My::Types qw/ValidAppName ValidAppComponent AppEnv/;
12594914 36
37my $app_tc = find_type_constraint(ValidAppName);
38ok $app_tc;
39ok !$app_tc->check('');
40ok $app_tc->check('MyApp');
41
42my $comp_tc = find_type_constraint(ValidAppComponent);
43ok $comp_tc;
44ok !$comp_tc->check('');
45ok !$comp_tc->check('MyApp');
46ok $comp_tc->check('MyApp::Model::Foo');
47
8dccaa92 48my $env_tc = my $comp_tc = find_type_constraint(AppEnv);
49ok $env_tc;
50#ok !$env_tc->check('');
51#ok !$env_tc->check('
12594914 52is $app_tc->coerce('MyApp::Model::Foo'), 'MyApp';
53
54done_testing;
55