summaryrefslogtreecommitdiff
path: root/lib/WebService/ForecastIo
diff options
context:
space:
mode:
authorGianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>2013-11-07 11:32:13 +0000
committerGianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>2013-11-07 12:06:25 +0000
commit022152630a9084fbc604f0d06b0005d97747b50d (patch)
tree8fa95f6ee8c70615a140519b93671a3e11376249 /lib/WebService/ForecastIo
parentexclude "sources" in forecast call (diff)
downloadHomePanel-022152630a9084fbc604f0d06b0005d97747b50d.tar.gz
HomePanel-022152630a9084fbc604f0d06b0005d97747b50d.tar.bz2
HomePanel-022152630a9084fbc604f0d06b0005d97747b50d.zip
migrate to Moo: forecast client
Diffstat (limited to 'lib/WebService/ForecastIo')
-rw-r--r--lib/WebService/ForecastIo/Alert.pm31
-rw-r--r--lib/WebService/ForecastIo/DataBlock.pm23
-rw-r--r--lib/WebService/ForecastIo/DataPoint.pm30
-rw-r--r--lib/WebService/ForecastIo/DataSpan.pm11
-rw-r--r--lib/WebService/ForecastIo/Response.pm28
-rw-r--r--lib/WebService/ForecastIo/Types.pm55
6 files changed, 101 insertions, 77 deletions
diff --git a/lib/WebService/ForecastIo/Alert.pm b/lib/WebService/ForecastIo/Alert.pm
index d402fa2..af826d8 100644
--- a/lib/WebService/ForecastIo/Alert.pm
+++ b/lib/WebService/ForecastIo/Alert.pm
@@ -1,38 +1,25 @@
package WebService::ForecastIo::Alert;
-use Moose;
-use Moose::Util::TypeConstraints;
-use MooseX::Types::URI 'Uri';
-use MooseX::Types::DateTime;
-
-class_type 'WebService::ForecastIo::Alert';
-
-subtype 'WebService::ForecastIo::AlertArray',
- as 'ArrayRef[WebService::ForecastIo::Alert]';
-
-coerce 'WebService::ForecastIo::Alert', from 'HashRef',
- via { WebService::ForecastIo::Alert->new($_) };
-
-coerce 'WebService::ForecastIo::AlertArray', from 'ArrayRef[HashRef]',
- via {
- my $array = $_;
- [ map { WebService::ForecastIo::Alert->new($_) }
- @$array ]
- };
+use Moo;
+use namespace::autoclean;
+use Types::Standard -all;
+use Types::URI 'Uri';
+use Types::DateTime 'DateTimeT';
has title => (
is => 'ro',
- isa => 'Str',
+ isa => Str,
);
has expires => (
is => 'ro',
- isa => 'DateTime',
- coerce => 1,
+ isa => DateTimeT,
+ coerce => DateTimeT->coercion,
);
has uri => (
is => 'ro',
isa => Uri,
+ coerce => Uri->coercion,
);
1;
diff --git a/lib/WebService/ForecastIo/DataBlock.pm b/lib/WebService/ForecastIo/DataBlock.pm
index 9885c42..2b737ca 100644
--- a/lib/WebService/ForecastIo/DataBlock.pm
+++ b/lib/WebService/ForecastIo/DataBlock.pm
@@ -1,28 +1,21 @@
package WebService::ForecastIo::DataBlock;
-use Moose;
-use Moose::Util::TypeConstraints;
-use WebService::ForecastIo::DataPoint;
+use Moo;
+use namespace::autoclean;
+use Types::Standard -all;
+use WebService::ForecastIo::Types -all;
use WebService::ForecastIo::DataSpan;
-class_type 'WebService::ForecastIo::DataBlock';
-
-coerce 'WebService::ForecastIo::DataBlock', from 'HashRef',
- via { WebService::ForecastIo::DataBlock->new($_) };
-
has [qw(summary icon)] => (
is => 'ro',
- isa => 'Str',
+ isa => Str,
);
has data => (
is => 'ro',
- isa => 'WebService::ForecastIo::DataPointArray',
- coerce => 1,
- traits => [ 'Array' ],
- handles => {
- data_points => 'elements',
- }
+ isa => DataPointArray,
+ coerce => DataPointArray->coercion,
);
+sub data_points { @{$_[0]->data} }
sub spans_by_string {
my ($self,$field) = @_;
diff --git a/lib/WebService/ForecastIo/DataPoint.pm b/lib/WebService/ForecastIo/DataPoint.pm
index ba06fa1..47ef659 100644
--- a/lib/WebService/ForecastIo/DataPoint.pm
+++ b/lib/WebService/ForecastIo/DataPoint.pm
@@ -1,35 +1,21 @@
package WebService::ForecastIo::DataPoint;
-use Moose;
-use Moose::Util::TypeConstraints;
-use MooseX::Types::DateTime;
-
-class_type 'WebService::ForecastIo::DataPoint';
-
-subtype 'WebService::ForecastIo::DataPointArray',
- as 'ArrayRef[WebService::ForecastIo::DataPoint]';
-
-coerce 'WebService::ForecastIo::DataPoint', from 'HashRef',
- via { WebService::ForecastIo::DataPoint->new($_) };
-
-coerce 'WebService::ForecastIo::DataPointArray', from 'ArrayRef[HashRef]',
- via {
- my $array = $_;
- [ map { WebService::ForecastIo::DataPoint->new($_) }
- @$array ]
- };
+use Moo;
+use namespace::autoclean;
+use Types::DateTime 'DateTimeT';
+use Types::Standard -all;
has [qw( time
sunriseTime sunsetTime
precipIntensityMaxTime
temperatureMinTime temperatureMaxTime )] => (
is => 'ro',
- isa => 'DateTime',
- coerce => 1,
+ isa => DateTimeT,
+ coerce => DateTimeT->coercion,
);
has [qw(summary icon precipType)] => (
is => 'ro',
- isa => 'Str',
+ isa => Str,
);
has [qw( precipIntensity precipIntensityMax
@@ -40,7 +26,7 @@ has [qw( precipIntensity precipIntensityMax
cloudCover
pressure visibility ozone )] => (
is => 'ro',
- isa => 'Num',
+ isa => Num,
);
1;
diff --git a/lib/WebService/ForecastIo/DataSpan.pm b/lib/WebService/ForecastIo/DataSpan.pm
index 256f207..4911442 100644
--- a/lib/WebService/ForecastIo/DataSpan.pm
+++ b/lib/WebService/ForecastIo/DataSpan.pm
@@ -1,17 +1,20 @@
package WebService::ForecastIo::DataSpan;
-use Moose;
-use MooseX::Types::DateTime;
+use Moo;
+use namespace::autoclean;
+use Types::DateTime 'DateTimeT';
has start_time => (
is => 'ro',
- isa => 'DateTime',
+ isa => DateTimeT,
+ coerce => DateTimeT->coercion,
required => 1,
);
has stop_time => (
is => 'ro',
writer => '_set_stop_time',
- isa => 'DateTime',
+ isa => DateTimeT,
+ coerce => DateTimeT->coercion,
required => 1,
);
diff --git a/lib/WebService/ForecastIo/Response.pm b/lib/WebService/ForecastIo/Response.pm
index e217c70..24c5324 100644
--- a/lib/WebService/ForecastIo/Response.pm
+++ b/lib/WebService/ForecastIo/Response.pm
@@ -1,46 +1,46 @@
package WebService::ForecastIo::Response;
-use Moose;
-use WebService::ForecastIo::DataPoint;
-use WebService::ForecastIo::DataBlock;
-use WebService::ForecastIo::Alert;
+use Moo;
+use namespace::autoclean;
+use Types::Standard -all;
+use WebService::ForecastIo::Types -all;
use JSON;
has 'currently' => (
is => 'ro',
- isa => 'WebService::ForecastIo::DataPoint',
- coerce => 1,
+ isa => DataPoint,
+ coerce => DataPoint->coercion,
);
has [qw(daily hourly minutely)] => (
is => 'ro',
- isa => 'WebService::ForecastIo::DataBlock',
- coerce => 1,
+ isa => DataBlock,
+ coerce => DataBlock->coercion,
);
has [qw(latitude longitude)] => (
is => 'ro',
- isa => 'Num',
+ isa => Num,
);
has timezone => (
is => 'ro',
- isa => 'Str',
+ isa => Str,
);
has offset => (
is => 'ro',
- isa => 'Num',
+ isa => Num,
);
has alerts => (
is => 'ro',
- isa => 'WebService::ForecastIo::AlertArray',
- coerce => 1,
+ isa => AlertArray,
+ coerce => AlertArray->coercion,
);
has flags => (
is => 'ro',
- isa => 'HashRef',
+ isa => HashRef,
);
around BUILDARGS => sub {
diff --git a/lib/WebService/ForecastIo/Types.pm b/lib/WebService/ForecastIo/Types.pm
new file mode 100644
index 0000000..cc8dac2
--- /dev/null
+++ b/lib/WebService/ForecastIo/Types.pm
@@ -0,0 +1,55 @@
+package WebService::ForecastIo::Types;
+use strict;
+use warnings;
+use namespace::autoclean;
+use Type::Library -base, -declare =>
+ qw(
+ Alert AlertArray
+ DataBlock
+ DataPoint DataPointArray
+ );
+use Type::Utils -all;
+use Types::Standard -types;
+
+class_type Alert, { class => 'WebService::ForecastIo::Alert' };
+
+declare AlertArray, as ArrayRef[Alert];
+
+coerce Alert, from HashRef, via {
+ require WebService::ForecastIo::Alert;
+ WebService::ForecastIo::Alert->new($_);
+};
+
+coerce AlertArray, from ArrayRef[HashRef], via {
+ require WebService::ForecastIo::Alert;
+ my $array = $_;
+ [ map { WebService::ForecastIo::Alert->new($_) }
+ @$array ]
+};
+
+
+class_type DataBlock, { class => 'WebService::ForecastIo::DataBlock' };
+
+coerce DataBlock, from HashRef, via {
+ require WebService::ForecastIo::DataBlock;
+ WebService::ForecastIo::DataBlock->new($_);
+};
+
+
+class_type DataPoint, { class => 'WebService::ForecastIo::DataPoint' };
+
+declare DataPointArray, as ArrayRef[DataPoint];
+
+coerce DataPoint, from HashRef, via {
+ require WebService::ForecastIo::DataPoint;
+ WebService::ForecastIo::DataPoint->new($_);
+};
+
+coerce DataPointArray, from ArrayRef[HashRef], via {
+ require WebService::ForecastIo::DataPoint;
+ my $array = $_;
+ [ map { WebService::ForecastIo::DataPoint->new($_) }
+ @$array ]
+};
+
+1;