diff options
author | Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> | 2013-11-07 11:32:13 +0000 |
---|---|---|
committer | Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> | 2013-11-07 12:06:25 +0000 |
commit | 022152630a9084fbc604f0d06b0005d97747b50d (patch) | |
tree | 8fa95f6ee8c70615a140519b93671a3e11376249 /lib/Types | |
parent | exclude "sources" in forecast call (diff) | |
download | HomePanel-022152630a9084fbc604f0d06b0005d97747b50d.tar.gz HomePanel-022152630a9084fbc604f0d06b0005d97747b50d.tar.bz2 HomePanel-022152630a9084fbc604f0d06b0005d97747b50d.zip |
migrate to Moo: forecast client
Diffstat (limited to 'lib/Types')
-rw-r--r-- | lib/Types/DateTime.pm | 20 | ||||
-rw-r--r-- | lib/Types/URI.pm | 15 |
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/Types/DateTime.pm b/lib/Types/DateTime.pm new file mode 100644 index 0000000..d13f0d5 --- /dev/null +++ b/lib/Types/DateTime.pm @@ -0,0 +1,20 @@ +package Types::DateTime; +use strict; +use warnings; +use namespace::autoclean; +use Type::Library -base, -declare => 'DateTimeT'; +use Type::Utils -all; +use Types::Standard -types; + +class_type DateTimeT, { class => 'DateTime' }; +coerce DateTimeT, from Num, via { + require DateTime; + DateTime->from_epoch(epoch => $_ ); +}; +coerce DateTimeT, from Str, via { + require DateTime::Format::ISO8601; + s{([+-])(\d\d)(\d\d)\z}{$1$2:$3}; + DateTime::Format::ISO8601->new->parse_datetime($_) +}; + +1; diff --git a/lib/Types/URI.pm b/lib/Types/URI.pm new file mode 100644 index 0000000..0bb4ae5 --- /dev/null +++ b/lib/Types/URI.pm @@ -0,0 +1,15 @@ +package Types::URI; +use strict; +use warnings; +use namespace::autoclean; +use Type::Library -base, -declare => 'Uri'; +use Type::Utils -all; +use Types::Standard -types; + +class_type Uri, { class => 'URI' }; +coerce Uri, from Str, via { + require URI; + URI->new($_); +}; + +1; |