summaryrefslogtreecommitdiff
path: root/lib/WebService/TFL/Bus/ResponseTypeRole.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/WebService/TFL/Bus/ResponseTypeRole.pm')
-rw-r--r--lib/WebService/TFL/Bus/ResponseTypeRole.pm40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/WebService/TFL/Bus/ResponseTypeRole.pm b/lib/WebService/TFL/Bus/ResponseTypeRole.pm
new file mode 100644
index 0000000..6cfd460
--- /dev/null
+++ b/lib/WebService/TFL/Bus/ResponseTypeRole.pm
@@ -0,0 +1,40 @@
+package WebService::TFL::Bus::ResponseTypeRole;
+use MooseX::Role::Parameterized;
+use WebService::TFL::Bus::Fields;
+use WebService::TFL::Bus::Types 'DateTimeMillis';
+
+parameter type => (
+ isa => 'Str',
+ required => 1,
+);
+
+role {
+ my $p = shift;
+ my $method = $p->type . '_return_fields';
+ my @fields = WebService::TFL::Bus::Fields->$method;
+
+ for my $field (@fields) {
+ has $field => (
+ is => 'ro',
+ ( $field =~ /Time$/ ? (
+ isa => DateTimeMillis,
+ coerce => 1,
+ ) : () ),
+ );
+ }
+
+ method new_from_array => sub {
+ my ($class,$return_set,$array) = @_;
+
+ my %args;
+ my $i=1;
+ for my $field (@fields) {
+ next unless exists $return_set->{$field};
+ $args{$field}=$array->[$i];
+ ++$i;
+ }
+ return $class->new(\%args);
+ }
+};
+
+1;