Module/Install/YAML/Tests.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 97 CC 7 SCAR 26.4
CC
7
Cov
0%
use_yaml_tests
20.0
_copy_file
20.0
BEGIN
2.0
CRAP 14.0
1 package Module::Install::TestBase;
2 use strict;
3  
4 use Module::Install::Base;
5  
6 use vars qw($VERSION @ISA);
7 BEGIN {
8 $VERSION = '0.10';
9 @ISA = 'Module::Install::Base';
10 }
11  
12 sub use_yaml_tests {
13 my $self = shift;
14 my $base_env_name = 'PERL_YAML_TESTS_BASE';
15 my $base = $ENV{$base_env_name}
16 or die "$base_env_name environment variable is not set";
17 die "'$base' is an invalid value for $base_env_name"
18 unless
19 -d "$base/yaml-tests" and
20 -d "$base/t";
21 my $config_file = 't/yaml_tests.yaml';
22 die "You must define the file $config_file to 'use_yaml_tests'"
23 unless -f $config_file;
24 eval "use YAML::Tiny 1.08; 1" or die $@;
25  
26 my ($config) = YAML::Tiny::LoadFile($config_file);
27  
28 die "'yaml_module' not defined in $config_file"
29 unless defined $config->{yaml_module};
30 $config->{use_blib} ||= 0;
31 $config->{exclude} ||= [];
32  
33 print "TODO - Copy YAML::Tests test files to here\n";
34  
35 for (
36 "$base/t/TestYAMLTests.pm",
37 "$base/t/data",
38 glob("$base/yaml-tests/*"),
39 ) {
40 $self->_copy_file($_, $config);
41 }
42 }
43  
44 sub _copy_file {
45 my ($self, $source, $config) = @_;
46 my $file = $source;
47 $file =~ s/.*[\/\\]//;
48 if (grep {$_ eq $file} @{$config->{exclude}}) {
49 print ">> Excluding t/$file\n";
50 return;
51 }
52 if (-d $source && -e "t/$file") {
53 my $command = "rm -fr t/$file";
54 print ">> $command\n";
55 system($command) == 0 or die "Failed";
56 }
57 if (-e "t/$file" and -M $source >= -M "t/$file") {
58 print ">> Skipping t/$file\n";
59 return;
60 }
61 my $command = "cp -r $source t/$file";
62 print ">> $command\n";
63 system($command) == 0 or die "Failed";
64 }
65  
66 1;
67  
68 =head1 NAME
69  
70 Module::Install::TestBase - Module::Install Support for YAML::Tests
71  
72 =head1 SYNOPSIS
73  
74 # Example Makefile.PL
75 use inc::Module::Install;
76  
77 name 'YAML::Foo';
78 all_from 'lib/YAML/Foo.pm';
79  
80 use_yaml_tests;
81  
82 WriteAll;
83  
84 =head1 DESCRIPTION
85  
86 By adding the single line:
87  
88 use_yaml_tests;
89  
90 to your C<Module::Install> based C<Makefile.PL>, when you then run
91 the command:
92  
93 perl Makefile.PL
94  
95 the YAML::Tests test files will be copied into your module's C<t/>
96 directory.
97  
98 =head1 CONFIGURATION
99  
100 If you are using C<YAML::Tests> in your own YAML module, create a
101 file called C<t/yaml_tests.yaml>. Here is an example:
102  
103 # YAML::Tests Config File
104
105 # The name of your module
106 yaml_module: YAML::Syck
107
108 # Set this to '1' if your module uses XS
109 use_blib: 1
110
111 # List of test components to *not* copy to your module area
112 exclude:
113 - alias.t
114 - null.t
115  
116 =head1 AUTHOR
117  
118 Ingy döt Net <ingy@cpan.org>
119  
120 =head1 COPYRIGHT
121  
122 Copyright (c) 2007. Ingy döt Net. All rights reserved.
123  
124 This program is free software; you can redistribute it and/or modify it
125 under the same terms as Perl itself.
126  
127 See L<http://www.perl.com/perl/misc/Artistic.html>
128  
129 =cut