Test::mongod - run a temporrary instance of MongoDB
use Test::mongod; my $mongod = Test::mongod->new; # thats it, you get a mongod server on a random port and in a /tmp dir ... more $mongod->port; # get the port the server is listening on $mongod->dbpath; # get the db dir
Test::mongod automatically sets up a temporary instance of MongoDB and destroys it when the script ends.
The latest version of this is always at https://github.com/jshy/Test-mongod This is ALPHA code.
ALPHA
new
my $mongod = Test::mongod->new;
This creates a new instance of Test::mongod and instanciates a temporary MongoDB server This uses the moose BUILD method to go ahead and launche the server. This method blocks till the server is listening and ready to work.
Test::mongod
stop
$mongo->stop;
Stops the MongoDB instance and tears down the temporary directory. This method is called by DEMOLISH when the object goes out of scope.
The IP to bind the server on. Defaults to 127.0.0.1. Must be an IP on the localhost.
The port for the server to listen on. Defaults to a random port. Use this to get the port to feed to your client.
The diorectory for the database server to put ts files. This defaults to a /tmp directory that will be cleaned up when the script finishes. Changes this will cause the directory to persist. Must be a path on the localhost.
Contains the pid of the forked child process.
Jesse Shy <jshy@cpan.org>
Copyright 2014- Jesse Shy
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Test::mongod, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::mongod
CPAN shell
perl -MCPAN -e shell install Test::mongod
For more information on module installation, please visit the detailed CPAN module installation guide.