File Coverage

blib/lib/Test/Environment.pm
Criterion Covered Total %
statement 26 27 96.3
branch 2 4 50.0
condition n/a
subroutine 8 8 100.0
pod n/a
total 36 39 92.3


line stmt bran cond sub pod time code
1             package Test::Environment;
2              
3             =head1 NAME
4              
5             Test::Environment - Base module for loading Test::Environment::Plugin::*
6              
7             =head1 SYNOPSIS
8              
9             use Test::Environment qw{
10             PostgreSQL
11             Dump
12             };
13            
14             # now we have 'psql', 'dump_with_name', ... functions in current namespace.
15             # imported from Test::Environment::Plugin::PostreSQL and Test::Environment::Plugin::Dump
16              
17             eq_or_diff(
18             [ psql(
19             'switches' => '--expanded',
20             'command' => 'SELECT * FROM Table LEFT JOIN OtherTable USING (other_id) ORDER BY other_id;',
21             ) ],
22             [ dump_with_name('test_01.dump') ],
23             'check db loading',
24             );
25              
26             =head1 DESCRIPTION
27              
28             This is the base module to load Test::Environment::Plugin::* modules.
29              
30             Also sets:
31              
32             $ENV{'RUNNING_ENVIRONMENT'} = 'testing';
33              
34             The basic idea is to call all the plugins you will need in your testing
35             script. The plugins will export their routines so you can use them in your tests
36             easily. By the $ENV{'RUNNING_ENVIRONMENT'} you can announce that you are running
37             in the testing mode to all the components of your tool. For example MyApp::Config
38             module can decide uppon the %ENV from where to run the configuration file. (for testing
39             look in t/conf/ instead of conf/ for ordinary usage)
40              
41             =cut
42              
43 4     4   180902 use strict;
  4         7  
  4         99  
44 4     4   17 use warnings;
  4         6  
  4         158  
45              
46             our $VERSION = "0.07";
47              
48 4     4   2822 use Carp::Clan;
  4         9672  
  4         22  
49 4     4   1464 use English '-no_match_vars';
  4         3909  
  4         23  
50 4     4   1665 use File::Basename;
  4         6  
  4         331  
51              
52             BEGIN {
53 4     4   680 $ENV{'RUNNING_ENVIRONMENT'} = 'testing';
54             }
55              
56              
57             =head1 FUNCTIONS
58              
59             =head2 import()
60              
61             Will load choosen Test::Environment::Plugin::? plugins.
62              
63             =cut
64              
65             sub import {
66 4     4   37 my $package = shift;
67 4         9 my @args = @_;
68              
69 4         16 foreach my $plugin_name (@args) {
70 3 50       25 croak 'bad plugin name' if $plugin_name !~ m{^\w+(::\w+)*$}xms;
71            
72 3         9 my $plugin_module_name = 'Test::Environment::Plugin::'.$plugin_name;
73 3     3   157 eval 'use '.$plugin_module_name.';';
  3         1665  
  3         8  
  3         30  
74 3 50       46 if ($EVAL_ERROR) {
75 0         0 croak 'Failed to load "'.$plugin_module_name.'" - '.$EVAL_ERROR;
76             }
77             }
78             }
79              
80             1;
81              
82              
83             =head1 SEE ALSO
84              
85             Test::Environment::Plugin::* L
86              
87             =head1 AUTHOR
88              
89             Jozef Kutej, Ejkutej@cpan.orgE
90              
91             =head1 COPYRIGHT AND LICENSE
92              
93             Copyright (C) 2007 by Jozef Kutej
94              
95             This library is free software; you can redistribute it and/or modify
96             it under the same terms as Perl itself, either Perl version 5.8.8 or,
97             at your option, any later version of Perl 5 you may have available.
98              
99             =cut