package WebService::TFL::Bus::Response; use Moo; use Types::Standard -all; use WebService::TFL::Bus::Prediction; use namespace::clean; has predictions => ( is => 'ro', isa => ArrayRef[InstanceOf['WebService::TFL::Bus::Prediction']], ); sub new_from_response { my ($class,$response_data) = @_; return $class->new({ predictions => [ map { WebService::TFL::Bus::Prediction->new_from_response($_) } grep { $_->{'$type'} =~ /\bPrediction\b/ } $response_data->@* ], }); } 1;