File Coverage

lib/Test/DataDirs/Exporter.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 27 27 100.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Test::DataDirs::Exporter - manage t/data and t/temp directories for your tests
4              
5             =head1 VERSION
6              
7             version 0.1.0
8              
9             =head1 SYNOPSIS
10              
11             Like the base class L, this is a convenience which
12             provides data directories from which to source information for your
13             tests, and temp directories you can write data.
14              
15             Declare some temp and data directories you need in your test script as
16             below. These are implicitly relative to C<< t/temp/ >>
17             and C<< t/data/ >>. Then you may refer to them
18             using the imported variables, and assume the dirs
19             exist and that the temp dirs have been (re-)created.
20              
21             # File: t/test-01.t
22             use Test::DataDirs::Exporter (
23             temp => [temp_stuff => 'actual-dir',
24             more_temp => 'another-dir'],
25             data => [data_stuff => 'actual-dir'],
26             );
27              
28             print "My test data is checked into $data_stuff\n"
29             print "below $data_dir\n"
30             # Prints (except with absolute paths):
31             # My test data is checked into t/data/test-01/actual-dir
32             # below t/data/test-01
33              
34             print "I can write temp data into $temp_stuff\n"
35             print "and $more_temp, "below $temp_dir\n"
36             # Prints (except with absolute paths):
37             # I can write temp data into t/temp/test-01/actual-dir
38             # and t/temp/test-01/another-dir below t/data/test-01
39              
40              
41             =head1 DESCRIPTION
42              
43             =cut
44              
45             package Test::DataDirs::Exporter;
46 3     3   25166 use strict;
  3         6  
  3         149  
47 3     3   15 use warnings;
  3         6  
  3         83  
48 3     3   1430 use Test::DataDirs;
  3         7  
  3         68  
49 3     3   12 use Carp;
  3         6  
  3         354  
50             our @CARP_NOT = 'Test::DataDirs';
51              
52             our $VERSION = '0.1.0'; # VERSION
53              
54             sub import {
55 8     8   4229 my $package = shift;
56 8         24 my $target = caller;
57              
58 8         230 my $dirs = Test::DataDirs->new(@_)->dirs;
59 3     3   16 no strict 'refs';
  3         4  
  3         262  
60 3         32 for my $name (keys %$dirs) {
61 14         24 *{"${target}::$name"} = \$dirs->{$name};
  14         3032  
62             }
63             }
64              
65             1;