WWW::NationalRail - Perl interface to the UK rail timetable
use WWW::NationalRail; my $rail = WWW::NationalRail->new({ from => "London", to => "Cambridge", out_date => "18/12/05", out_type => "depart", out_hour => 9, out_minute => 0, ret_date => "18/12/05", ret_type => "depart", ret_hour => 17, ret_minute => 0, }); $rail->search or die $rail->error(); my $os = $rail->outward_summary; # array reference my $rs = $rail->return_summary; $os->[0]{depart} # "09:06" $os->[0]{arrive} # "10:25" $os->[0]{changes} # "0" $os->[0]{duration} # "1:19" my $od = $rail->outward_detail; my $rd = $rail->return_detail; $od->[0]->{duration}; # "1:19" my $legs = $od->[0]{legs} # array reference $legs->[0]{station} # "LONDON KINGS CROSS" $legs->[0]{arrive} # undef $legs->[0]{depart} # "09:06" $legs->[0]{travelby} # "Train" $legs->[0]{operator} # "WAGN RAIL" $rail->ret_hour(19); # change search parameters $rail->search(); # and search again
WWW::NationalRail is a Perl interface to the UK national rail timetable at http://www.nationalrail.co.uk/planmyjourney/
The constructor accepts the arguments for the search as a has reference. The from and to fields are required, the rest are optional and will use a National Rail supplied default.
Departure station.
Destination station.
Via station.
Outbound date in the format "DD/MM/YY". Defaults to today.
Possible values are "depart" to search by outbound departure time or "arrive" to search by outbound arrival time. Defaults to "depart".
Outbound hour, 0 to 23. Defaults to sometime in the near future.
Outbound minute, 0 to 59. Defaults to sometime in the near future.
Return date in the format "DD/MM/YY". Leave blank for one-way.
Similar to out_type. Either "depart or "arrive". Defaults to "depart".
Return hour, 0 to 23. Leave blank for one-way.
Return minute, 0 to 59. Leave blank for one-way.
Object method to run the search and parse the results.
Each returns a reference to an array of hashes. For journeys in one direction return_summary() will be undef. The hash representing a summary has four fields:
Time of departure.
Time of arrival.
Number of changes.
Duration of the journey.
Each returns a reference to an array of hashes. For journeys in one direction return_details() will be undef. The hash representing a journey has four two fields:
Reference to an array of hashes.
The legs hash has four five fields:
Name of the station.
Time of arrival at this station, undef for the first leg.
Time of departure from this station, undef for the last leg.
Means of transport, will usually be train, but could also be foot, coach, or tube.
The train operating company.
Edward Betts, <edward@debian.org>
<edward@debian.org>
Copyright (C) 2005 by Edward Betts
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.
To install WWW::NationalRail, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::NationalRail
CPAN shell
perl -MCPAN -e shell install WWW::NationalRail
For more information on module installation, please visit the detailed CPAN module installation guide.