Add a file to hold WebGUI types for Moose. Note, reads from the db come back as undef, so it has to be explicitly coerced.

This commit is contained in:
Colin Kuskie 2010-03-18 14:44:52 -07:00
parent bc466ab74f
commit a92a50046e

20
lib/WebGUI/Types.pm Normal file
View file

@ -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;