summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-06-16 22:23:03 -0500
committerJesse Luehrs <doy@tozt.net>2009-06-16 22:23:03 -0500
commit3f8cbe6bf3bf305c9bb77d8f15b1ad2143ee440a (patch)
tree397713a3aef10a0615a2d74fda07819c6c9303ed
parentafcde73887075e3befd4bf35815ee0f757b093b6 (diff)
downloadwww-unfuddle-3f8cbe6bf3bf305c9bb77d8f15b1ad2143ee440a.tar.gz
www-unfuddle-3f8cbe6bf3bf305c9bb77d8f15b1ad2143ee440a.zip
split type constraints out into a type lib, with proper coercionsHEADmaster
-rw-r--r--lib/WWW/Unfuddle/Meta/Types.pm20
-rw-r--r--lib/WWW/Unfuddle/Project.pm23
2 files changed, 34 insertions, 9 deletions
diff --git a/lib/WWW/Unfuddle/Meta/Types.pm b/lib/WWW/Unfuddle/Meta/Types.pm
new file mode 100644
index 0000000..344a231
--- /dev/null
+++ b/lib/WWW/Unfuddle/Meta/Types.pm
@@ -0,0 +1,20 @@
+package WWW::Unfuddle::Meta::Types;
+use Moose::Util::TypeConstraints;
+use DateTime::Format::ISO8601;
+use JSON;
+
+class_type 'JSON::Boolean';
+subtype 'WWW::Unfuddle::Bool', as 'Bool', where { !ref($_) };
+coerce 'WWW::Unfuddle::Bool', from 'JSON::Boolean',
+ via { $_ == JSON::true };
+
+# 2009-06-16T22:55:06Z
+class_type 'DateTime';
+subtype 'WWW::Unfuddle::DateTime', as 'DateTime';
+coerce 'WWW::Unfuddle::DateTime', from 'Str',
+ via { DateTime::Format::ISO8601->new->parse_datetime($_) };
+
+enum 'WWW::Unfuddle::Assignee' => qw(reporter none nochange);
+enum 'WWW::Unfuddle::ThemeColor' => qw(blue green grey orange purple red teal);
+
+1;
diff --git a/lib/WWW/Unfuddle/Project.pm b/lib/WWW/Unfuddle/Project.pm
index 5d0d79f..a675407 100644
--- a/lib/WWW/Unfuddle/Project.pm
+++ b/lib/WWW/Unfuddle/Project.pm
@@ -1,6 +1,6 @@
package WWW::Unfuddle::Project;
use Moose;
-use Moose::Util::TypeConstraints; # XXX
+use WWW::Unfuddle::Meta::Types;
has account_id => (
is => 'ro',
@@ -9,27 +9,30 @@ has account_id => (
has archived => (
is => 'ro',
- isa => 'Bool',
+ isa => 'WWW::Unfuddle::Bool',
+ coerce => 1,
);
has assignee_on_resolve => (
is => 'ro',
- isa => enum(qw(reporter none nochange)),
+ isa => 'WWW::Unfuddle::Assignee',
);
has close_ticket_simultaneously_default => (
is => 'ro',
- isa => 'Bool',
+ isa => 'WWW::Unfuddle::Bool',
+ coerce => 1,
);
has created_at => (
is => 'ro',
- isa => 'DateTime',
+ isa => 'WWW::Unfuddle::DateTime',
+ coerce => 1,
);
has default_ticket_report_id => (
is => 'ro',
- isa => 'Int',
+ isa => 'Maybe[Int]',
);
has description => (
@@ -44,7 +47,8 @@ has disk_usage => (
has enable_time_tracking => (
is => 'ro',
- isa => 'Bool',
+ isa => 'WWW::Unfuddle::Bool',
+ coerce => 1,
);
has id => (
@@ -59,7 +63,7 @@ has short_name => (
has theme => (
is => 'ro',
- isa => enum(qw(blue green grey orange purple red teal)),
+ isa => 'WWW::Unfuddle::ThemeColor',
);
has title => (
@@ -69,7 +73,8 @@ has title => (
has updated_at => (
is => 'ro',
- isa => 'DateTime',
+ isa => 'WWW::Unfuddle::DateTime',
+ coerce => 1,
);
__PACKAGE__->meta->make_immutable;