Add a Hash type to go along with Array types for handling JSON.

This commit is contained in:
Colin Kuskie 2010-07-14 16:31:20 -07:00
parent 79fa8cafa9
commit 2410ee2dd4

View file

@ -70,4 +70,18 @@ coerce 'WebGUI::Type::JSONArray'
=> via { return []; },
;
subtype 'WebGUI::Type::JSONHash'
=> as 'HashRef'
;
coerce 'WebGUI::Type::JSONHash'
=> from Str
=> via { my $struct = eval { JSON::from_json($_); }; $struct ||= {}; return $struct; },
;
coerce 'WebGUI::Type::JSONHash'
=> from Undef
=> via { return {}; },
;
1;