Add a Hash type to go along with Array types for handling JSON.
This commit is contained in:
parent
79fa8cafa9
commit
2410ee2dd4
1 changed files with 14 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue