Port ::Admin from Moose to Moo+Type::Tiny
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Admin / Types.pm
1 package # hide from PAUSE
2     DBIx::Class::Admin::Types;
3
4 use warnings;
5 use strict;
6
7 use Type::Library
8   -base,
9   -declare => qw(
10     Dir File
11     DBICConnectInfo
12     DBICArrayRef
13     DBICHashRef
14 );
15 use Type::Utils -all;
16 use Types::Standard qw/HashRef ArrayRef Str/;
17 use Path::Class;
18
19 class_type Dir, { class => 'Path::Class::Dir' };
20 class_type File, { class => 'Path::Class::File' };
21
22 coerce Dir, from Str, via { dir($_) };
23 coerce File, from Str, via { file($_) };
24
25 subtype DBICArrayRef,
26     as ArrayRef;
27
28 subtype DBICHashRef,
29     as HashRef;
30
31 coerce DBICArrayRef,
32   from Str,
33   via { _json_to_data ($_) };
34
35 coerce DBICHashRef,
36   from Str,
37   via { _json_to_data($_) };
38
39 subtype DBICConnectInfo,
40   as ArrayRef;
41
42 coerce DBICConnectInfo,
43   from Str, via { _json_to_data($_) },
44   from HashRef, via { [ $_ ] };
45
46 sub _json_to_data {
47   my ($json_str) = @_;
48   require JSON::Any;
49   my $json = JSON::Any->new(allow_barekey => 1, allow_singlequote => 1, relaxed=>1);
50   my $ret = $json->jsonToObj($json_str);
51   return $ret;
52 }
53
54 1;