NAME
Railway::Train - a running engine
VERSION
version 0.003
ATTRIBUTES
manager A Railway::Builder instance
index An index
way A Railway::Way instance
cargo A cargo for the train
done A code that will be passed after train reaches the end of the "way"
METHODS
power A switcher for train. Accepts true
or false
. Throws an exception if the same value provided twice
$train->power(1)->power(0)
# error
$train->power(1)->power(1);
run Run an engine
prepare Prepare an engine. Starts "index" to 0, "power" to 1, check stations; If something is wrong, an exception will be thrown
start
$train->start();
$train->start(sub {});
Prepare and run a train. You can provide a callback for "done"
can_run Check if a way has a stations more than current "index"
finish This method invokes a "done" callback. Will be called just after a train will have reached the end of the way
handle_station Safely executes a code
depart Increase index by one. Raises an error if index isn't defined
get_station Get current station
Description
An abstract instance for running your code. Prevent logic errors
Synopsis
my $bldr = Railway::Builder->new;
my $train = $bldr->build_train;
$train->way->add(sub { say "station1 " })->add(sub { say "station2" });
$train->start; # or $train->prepare->done(sub{say "done"})->run;
AUTHOR
alexbyk.com
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by alexbyk.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.