Commit | Line | Data |
71ef99d5 |
1 | package # hide from PAUSE |
2 | DBIx::Class::Admin::Types; |
3 | |
5292b35a |
4 | use warnings; |
5 | use strict; |
6 | |
a21416fa |
7 | use Type::Library |
8 | -base, |
9 | -declare => qw( |
10 | Dir File |
71ef99d5 |
11 | DBICConnectInfo |
a62dec82 |
12 | DBICArrayRef |
13 | DBICHashRef |
a21416fa |
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($_) }; |
71ef99d5 |
24 | |
a62dec82 |
25 | subtype DBICArrayRef, |
26 | as ArrayRef; |
27 | |
28 | subtype DBICHashRef, |
29 | as HashRef; |
30 | |
31 | coerce DBICArrayRef, |
a21416fa |
32 | from Str, |
71ef99d5 |
33 | via { _json_to_data ($_) }; |
34 | |
a62dec82 |
35 | coerce DBICHashRef, |
a21416fa |
36 | from Str, |
71ef99d5 |
37 | via { _json_to_data($_) }; |
38 | |
39 | subtype DBICConnectInfo, |
40 | as ArrayRef; |
41 | |
42 | coerce DBICConnectInfo, |
a21416fa |
43 | from Str, via { _json_to_data($_) }, |
44 | from HashRef, via { [ $_ ] }; |
71ef99d5 |
45 | |
46 | sub _json_to_data { |
47 | my ($json_str) = @_; |
a21416fa |
48 | require JSON::Any; |
71ef99d5 |
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; |