NAME
Railway::Train - a running engine
VERSION
version 0.0153
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;
DESCRIPTION
An abstract instance for running your code. Prevent logic errors
ATTRIBUTES
manager
A Railway::Builder instance
index
An index
way
A Railway::Way instance
cargo
Cargo for a train
done
A code that will be passed after train reaches the end of the "way"
METHODS
power
A switcher for a 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 dsl_stash "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 dsl_stash station
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.