System/Helper.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 47 CC 4 SCAR 17.6
CC
4
Cov
0%
get_nodes
12.0
get_param
6.0
BEGIN
2.0
CRAP 5.8
1 #
2 # Test::System::Helper
3 #
4 # Author(s): Pablo Fischer (pfischer@cpan.org)
5 # Created: 11/08/2009 14:03:24 PST 14:03:24
6 package Test::System::Helper;
7  
8 =head1 NAME
9  
10 Test::System::Helper - Helper for the Test::System
11  
12 =head1 DESCRIPTION
13  
14 The purpose of this module is to provide the easiness of getting the list of
15 nodes you want to test (if that is the case) and as well to let you fetch
16 the value of the params you specified in your L<Test::System> instance.
17  
18 =cut
19  
20 use strict;
21 use warnings;
22 use vars qw(@EXPORT @EXPORT_OK);
23 use Exporter qw(import);
24  
25 @EXPORT_OK = qw(get_nodes get_param);
26 @EXPORT = @EXPORT_OK;
27  
28 my @node_list;
29  
30 our $VERSION = '0.02';
31  
32 =head1 Functions
33  
34 =over 4
35  
36 =item B<get_nodes( )>
37  
38 Returns as an array the nodes you specified via L<Test::System>. It basically
39 joins splits by CSV the C<TEST_SYSTEM_NODES> environment variable value and
40 returns it.
41  
42 =cut
43 sub get_nodes {
44 if (@node_list) {
45 return @node_list;
46 }
47 if ($ENV{'TEST_SYSTEM_NODES'}) {
48 @node_list = split(',', $ENV{'TEST_SYSTEM_NODES'});
49 }
50 # We don't like duplicated nodes..
51 my %seen;
52 my @unique = grep { ! $seen{$_}++ } @node_list;
53 @node_list = @unique;
54 }
55  
56 =item B<get_param( $key )>
57  
58 Returns the parameter value of the given key.
59  
60 The key name is the same key passed to the L<Test::System>, not the environment
61 variable that is set by L<Test::System>.
62  
63 It returns the parameter by checking the environment variable that stores its
64 value. The name of the environments variables can be explained in the
65 L<Test::System> module, however a quick example will be:
66  
67 use Test::System::Helper;
68  
69 my $value = get_param('foo').
70  
71 # It will returns the value of: TEST_SYSTEM_FOO
72  
73 Please note that since the values come from the environment the only type of
74 data that will be returned will be scalar unless the key is not found then
75 C<undef> will be returned.
76  
77 =back
78  
79 =cut
80 sub get_param {
81 my ($key) = @_;
82  
83 use Data::Dumper;
84 $key = 'TEST_SYSTEM_' . uc($key);
85  
86 if (!defined $ENV{$key}) {
87 return undef;
88 }
89 return $ENV{$key};
90 }
91  
92 =head1 AUTHOR
93
94 Pablo Fischer, pablo@pablo.com.mx.
95
96  
97 =head1 COPYRIGHT
98
99 Copyright (C) 2009 by Pablo Fischer
100
101 This library is free software; you can redistribute it and/or modify
102 it under the same terms as Perl itself.
103  
104 =cut
105 1;
106