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:
parent
bc466ab74f
commit
a92a50046e
1 changed files with 20 additions and 0 deletions
20
lib/WebGUI/Types.pm
Normal file
20
lib/WebGUI/Types.pm
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue