diff --git a/lib/WebGUI/Types.pm b/lib/WebGUI/Types.pm new file mode 100644 index 000000000..6153656a5 --- /dev/null +++ b/lib/WebGUI/Types.pm @@ -0,0 +1,20 @@ +package WebGUI::Types; + +use Moose; +use Moose::Util::TypeConstraints; + +subtype 'WebGUI::Type::JSONArray' + => as 'ArrayRef' +; + +coerce 'WebGUI::Type::JSONArray' + => from Str + => via { my $struct = eval { JSON::from_json($_); }; $struct ||= []; return $struct; }, +; + +coerce 'WebGUI::Type::JSONArray' + => from Undef + => via { return []; }, +; + +1;