Net::Wait - Wait on startup until the specified ports are listening
# Use as a library
use Net::Wait -timeout => 10, 'perl.org:80';
# Or from the command line
# perl -MNet::Wait=perl.org:80 ...
When you import Net::Wait, you provide a list of TCP hosts and ports. It will then block until those ports are listening, or until it times out, in which case an error will be raised and execution will stop..
It is inspired in interface and functionality by the popular wait-for-it Bash script originally written by Giles Hall, and is in essence a convenience wrapper around Net::EmptyPort::wait_port.
Host / port pairs need to be provided as a single string with the host and the port separated by a colon (:). There are no default values: ports always need to be specified. If Net::Wait cannot parse these from the input it will throw an error.
They will be tested in the order they were provided.
Net::Wait accepts a number of options before the list of hosts to wait for. Passing an unknown option will raise a compile-time error, as will providing an invalid value to any valid option.
use Net::Wait -timeout => $seconds, ...;
Specify the maximum amount of time in seconds that Net::Wait should wait for before aborting.
The same value will be used for all the provided host/port pairs, and will apply independently to each of them. If any takes longer than the timeout to become available, an error will be raised and execution will abort.
If you need different timeouts to apply to different hosts, Net::Wait can be imported multiple times with different options, since each set of options will only apply that one time.
Defaults to 10 seconds. Set to a negative value for no timeout.
use Net::Wait -verbose, ...;
If present, Net::Wait will print output about what it is waiting for and for how long it will wait.
Defaults to off, for no output.
The original bash implementation.
The underlying library used by Net::Wait.
An older library that also allows to check whether a port is open. The interface is more limited, but unlike Net::EmptyPort, it has no non-core dependencies.
This module exists because Owen Allsopp thought it would be a good idea.
Copyright 2022 José Joaquín Atria
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
To install Net::Wait, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.