summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>2013-11-07 11:59:14 +0000
committerGianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>2013-11-07 12:06:25 +0000
commit75fe8d4a588abd4da62685ab64dfcaafc07cfae6 (patch)
tree944e055d0cc575b5c10d7b8c6d1f6498006fdb7e /lib
parentmigrate to Moo: forecast client (diff)
downloadHomePanel-75fe8d4a588abd4da62685ab64dfcaafc07cfae6.tar.gz
HomePanel-75fe8d4a588abd4da62685ab64dfcaafc07cfae6.tar.bz2
HomePanel-75fe8d4a588abd4da62685ab64dfcaafc07cfae6.zip
migrate to Moo: bus client
Diffstat (limited to 'lib')
-rw-r--r--lib/WebService/TFL/Bus.pm14
-rw-r--r--lib/WebService/TFL/Bus/Request.pm5
-rw-r--r--lib/WebService/TFL/Bus/Response.pm7
-rw-r--r--lib/WebService/TFL/Bus/Response/BaseVersion.pm2
-rw-r--r--lib/WebService/TFL/Bus/Response/FlexibleMessage.pm6
-rw-r--r--lib/WebService/TFL/Bus/Response/Prediction.pm6
-rw-r--r--lib/WebService/TFL/Bus/Response/Stop.pm6
-rw-r--r--lib/WebService/TFL/Bus/Response/URAVersion.pm2
-rw-r--r--lib/WebService/TFL/Bus/ResponseTypeRole.pm20
-rw-r--r--lib/WebService/TFL/Bus/Types.pm18
10 files changed, 47 insertions, 39 deletions
diff --git a/lib/WebService/TFL/Bus.pm b/lib/WebService/TFL/Bus.pm
index 60ec5c9..6352a5d 100644
--- a/lib/WebService/TFL/Bus.pm
+++ b/lib/WebService/TFL/Bus.pm
@@ -1,14 +1,14 @@
package WebService::TFL::Bus;
-use Moose;
-use Moose::Util::TypeConstraints;
-use MooseX::Types::URI 'Uri';
-use WebService::TFL::Bus::Response;
+use Moo;
use namespace::autoclean;
+use Types::URI 'Uri';
+use Type::Utils -all;
+use WebService::TFL::Bus::Response;
has user_agent => (
isa => duck_type(['get']),
- is => 'ro',
- lazy_build => 1,
+ is => 'lazy',
+
);
sub _build_user_agent {
require LWP::UserAgent;
@@ -20,7 +20,7 @@ sub _build_user_agent {
has uri => (
isa => Uri,
is => 'ro',
- coerce => 1,
+ coerce => Uri->coercion,
default => 'http://countdown.api.tfl.gov.uk/interfaces/ura/instant_V1',
);
diff --git a/lib/WebService/TFL/Bus/Request.pm b/lib/WebService/TFL/Bus/Request.pm
index cf35459..dda6586 100644
--- a/lib/WebService/TFL/Bus/Request.pm
+++ b/lib/WebService/TFL/Bus/Request.pm
@@ -1,5 +1,6 @@
package WebService::TFL::Bus::Request;
-use Moose;
+use Moo;
+use Types::Standard -all;
use WebService::TFL::Bus::Fields;
use namespace::autoclean;
@@ -12,7 +13,7 @@ for my $field (WebService::TFL::Bus::Fields->query_fields) {
has ReturnList => (
is => 'rw',
- isa => 'ArrayRef',
+ isa => ArrayRef,
predicate => 'has_ReturnList',
);
diff --git a/lib/WebService/TFL/Bus/Response.pm b/lib/WebService/TFL/Bus/Response.pm
index a4aa056..4251228 100644
--- a/lib/WebService/TFL/Bus/Response.pm
+++ b/lib/WebService/TFL/Bus/Response.pm
@@ -1,6 +1,8 @@
package WebService::TFL::Bus::Response;
-use Moose;
+use Moo;
use Class::Load 'load_class';
+use Type::Utils -all;
+use Types::Standard -all;
use JSON;
use namespace::autoclean;
@@ -21,8 +23,7 @@ for my $field (values %line_map) {
load_class($class);
has $field => (
is => 'ro',
- isa => "ArrayRef[$class]",
- traits => [ 'Array' ],
+ isa => ArrayRef[class_type { class => $class }],
);
}
diff --git a/lib/WebService/TFL/Bus/Response/BaseVersion.pm b/lib/WebService/TFL/Bus/Response/BaseVersion.pm
index 37b2ddb..07edbcb 100644
--- a/lib/WebService/TFL/Bus/Response/BaseVersion.pm
+++ b/lib/WebService/TFL/Bus/Response/BaseVersion.pm
@@ -1,5 +1,5 @@
package WebService::TFL::Bus::Response::BaseVersion;
-use Moose;
+use Moo;
use namespace::autoclean;
has Version => (
diff --git a/lib/WebService/TFL/Bus/Response/FlexibleMessage.pm b/lib/WebService/TFL/Bus/Response/FlexibleMessage.pm
index 11b7b1a..603ef6b 100644
--- a/lib/WebService/TFL/Bus/Response/FlexibleMessage.pm
+++ b/lib/WebService/TFL/Bus/Response/FlexibleMessage.pm
@@ -1,5 +1,7 @@
package WebService::TFL::Bus::Response::FlexibleMessage;
-use Moose;
-with 'WebService::TFL::Bus::ResponseTypeRole' => { type => 'flexible' };
+use Moo;
+use namespace::autoclean;
+use WebService::TFL::Bus::ResponseTypeRole;
+with ResponseTypeRole('flexible');
1;
diff --git a/lib/WebService/TFL/Bus/Response/Prediction.pm b/lib/WebService/TFL/Bus/Response/Prediction.pm
index d3ea931..49a4b76 100644
--- a/lib/WebService/TFL/Bus/Response/Prediction.pm
+++ b/lib/WebService/TFL/Bus/Response/Prediction.pm
@@ -1,5 +1,7 @@
package WebService::TFL::Bus::Response::Prediction;
-use Moose;
-with 'WebService::TFL::Bus::ResponseTypeRole' => { type => 'prediction' };
+use Moo;
+use namespace::autoclean;
+use WebService::TFL::Bus::ResponseTypeRole;
+with ResponseTypeRole('prediction');
1;
diff --git a/lib/WebService/TFL/Bus/Response/Stop.pm b/lib/WebService/TFL/Bus/Response/Stop.pm
index 3c98ca5..30f2f91 100644
--- a/lib/WebService/TFL/Bus/Response/Stop.pm
+++ b/lib/WebService/TFL/Bus/Response/Stop.pm
@@ -1,5 +1,7 @@
package WebService::TFL::Bus::Response::Stop;
-use Moose;
-with 'WebService::TFL::Bus::ResponseTypeRole' => { type => 'stop' };
+use Moo;
+use namespace::autoclean;
+use WebService::TFL::Bus::ResponseTypeRole;
+with ResponseTypeRole('stop');
1;
diff --git a/lib/WebService/TFL/Bus/Response/URAVersion.pm b/lib/WebService/TFL/Bus/Response/URAVersion.pm
index 38c8a62..fc0b41f 100644
--- a/lib/WebService/TFL/Bus/Response/URAVersion.pm
+++ b/lib/WebService/TFL/Bus/Response/URAVersion.pm
@@ -1,5 +1,5 @@
package WebService::TFL::Bus::Response::URAVersion;
-use Moose;
+use Moo;
use namespace::autoclean;
for my $field (qw(Version TimeStamp)) {
diff --git a/lib/WebService/TFL/Bus/ResponseTypeRole.pm b/lib/WebService/TFL/Bus/ResponseTypeRole.pm
index 6cfd460..7f48419 100644
--- a/lib/WebService/TFL/Bus/ResponseTypeRole.pm
+++ b/lib/WebService/TFL/Bus/ResponseTypeRole.pm
@@ -1,16 +1,14 @@
package WebService::TFL::Bus::ResponseTypeRole;
-use MooseX::Role::Parameterized;
+use Package::Variant
+ importing => [ 'Moo::Role'],
+ subs => [ 'has' ];
use WebService::TFL::Bus::Fields;
use WebService::TFL::Bus::Types 'DateTimeMillis';
-parameter type => (
- isa => 'Str',
- required => 1,
-);
+sub make_variant {
+ my ($class,$target_package,$type) = @_;
-role {
- my $p = shift;
- my $method = $p->type . '_return_fields';
+ my $method = $type . '_return_fields';
my @fields = WebService::TFL::Bus::Fields->$method;
for my $field (@fields) {
@@ -18,12 +16,12 @@ role {
is => 'ro',
( $field =~ /Time$/ ? (
isa => DateTimeMillis,
- coerce => 1,
+ coerce => DateTimeMillis->coercion,
) : () ),
);
}
- method new_from_array => sub {
+ install new_from_array => sub {
my ($class,$return_set,$array) = @_;
my %args;
@@ -35,6 +33,6 @@ role {
}
return $class->new(\%args);
}
-};
+}
1;
diff --git a/lib/WebService/TFL/Bus/Types.pm b/lib/WebService/TFL/Bus/Types.pm
index 9b569f5..e67fe32 100644
--- a/lib/WebService/TFL/Bus/Types.pm
+++ b/lib/WebService/TFL/Bus/Types.pm
@@ -1,12 +1,14 @@
package WebService::TFL::Bus::Types;
-use MooseX::Types -declare => [
- 'DateTimeMillis'
-];
-use MooseX::Types::Moose 'Num';
-use MooseX::Types::DateTime 'DateTime';
+use Type::Library -base, -declare => 'DateTimeMillis';
+use Types::Standard -all;
+use Type::Utils -all;
+use Types::DateTime 'DateTimeT';
+use namespace::autoclean;
-subtype DateTimeMillis, as DateTime;
-coerce DateTimeMillis, from Num,
- via { 'DateTime'->from_epoch( epoch => $_ / 1000 ) };
+declare DateTimeMillis, as DateTimeT;
+coerce DateTimeMillis, from Num, via {
+ require DateTime;
+ DateTime->from_epoch( epoch => $_ / 1000 )
+};
1;