Test::Environment - Base module for loading Test::Environment::Plugin::*


Test-Environment documentation Contained in the Test-Environment distribution.

Index


Code Index:

NAME

Top

Test::Environment - Base module for loading Test::Environment::Plugin::*

SYNOPSIS

Top

	use Test::Environment qw{
		PostgreSQL
		Dump
	};

	# now we have 'psql', 'dump_with_name', ... functions in current namespace.
	# imported from Test::Environment::Plugin::PostreSQL and Test::Environment::Plugin::Dump

	eq_or_diff(
		[ psql(
			'switches' => '--expanded',
			'command'  => 'SELECT * FROM Table LEFT JOIN OtherTable USING (other_id) ORDER BY other_id;',
		) ],
		[ dump_with_name('test_01.dump') ],
		'check db loading',
	);

DESCRIPTION

Top

This is the base module to load Test::Environment::Plugin::* modules.

Also sets:

	$ENV{'RUNNING_ENVIRONMENT'} = 'testing';

The basic idea is to call all the plugins you will need in your testing script. The plugins will export their routines so you can use them in your tests easily. By the $ENV{'RUNNING_ENVIRONMENT'} you can announce that you are running in the testing mode to all the components of your tool. For example MyApp::Config module can decide uppon the %ENV from where to run the configuration file. (for testing look in t/conf/ instead of conf/ for ordinary usage)

FUNCTIONS

Top

import()

Will load choosen Test::Environment::Plugin::? plugins.

SEE ALSO

Top

Test::Environment::Plugin::* http://search.cpan.org/search?query=Test%3A%3AEnvironment%3A%3APlugin%3A%3A&mode=module

AUTHOR

Top

Jozef Kutej, <jkutej@cpan.org>

COPYRIGHT AND LICENSE

Top


Test-Environment documentation Contained in the Test-Environment distribution.
package Test::Environment;

use strict;
use warnings;

our $VERSION = '0.06';

use Carp::Clan;
use English '-no_match_vars';
use File::Basename;

BEGIN {
	$ENV{'RUNNING_ENVIRONMENT'} = 'testing';
}


sub import {
	my $package = shift;
	my @args    = @_;

	foreach my $plugin_name (@args) {
		croak 'bad plugin name' if $plugin_name !~ m{^\w+(::\w+)*$}xms;
		
		my $plugin_module_name = 'Test::Environment::Plugin::'.$plugin_name; 
		eval 'use '.$plugin_module_name.';';
		if ($EVAL_ERROR) {
			croak 'Failed to load "'.$plugin_module_name.'" - '.$EVAL_ERROR;
		}
	}
}

1;