From a92a50046eeb5597cbc32ef9e9f346d75823643a Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 18 Mar 2010 14:44:52 -0700 Subject: [PATCH] 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. --- lib/WebGUI/Types.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/WebGUI/Types.pm 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;