lib/Test/File/ShareDir.pm

filter: Statementstmt 93.1% 68 / 73 Branchbran 78.5% 11 / 14 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 84.2% 96 / 114 CC 14 SCAR 14.5
CC
14
Cov
85%
import
8.1
with_dist_dir
4.5
with_module_dir
4.5
CRAP 4.3
« lib/Test/File/ShareDir/Utils.pm ↑ Summary lib/Test/File/ShareDir/TempDirObject.pm »
1 6 ▶use 5.006; # pragmas
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Test::File::ShareDir;
6  
7 6 our $VERSION = '1.001002';
8  
9 # ABSTRACT: Create a Fake ShareDir for your modules for testing.
10  
11 6 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24 6 ▶use File::ShareDir 1.00 qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 ▶use Exporter qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶use Test::File::ShareDir::Utils qw( extract_dashes );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 6 ▶use parent qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 6 our @EXPORT_OK = qw( with_dist_dir with_module_dir );
31  
32 5 ▶sub import {
Subroutine import: called CC=8 SCAR=20.9
33 5 my ( $package, @args ) = @_;
34  
35 5 my ( @imports, %params );
36  
37 # ->import( { }, qw( imports ) )
38 5 ▶ if ( 'HASH' eq ref $args[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('HASH' eq ref $args[0]) { } 0 5 5
39 0 %params = %{ shift @args };
40 0 @imports = @args;
41 }
42 else {
43 # ->import( -arg => value, -arg => value, @imports );
44 5 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 7 5 12
45 7 ▶ if ( $args[0] =~ /\A-(.*)\z/msx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] =~ /\A-(.*)\z/msx) 5 2 7
46 5 $params{ $args[0] } = $args[1];
47 5 splice @args, 0, 2, ();
48 5 next;
49 }
50 2 push @imports, shift @args;
51 }
52 }
53  
54 5 ▶ if ( keys %params ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %params) 3 2 5
55 3 require Test::File::ShareDir::TempDirObject;
56  
57 3 my $tempdir_object = Test::File::ShareDir::TempDirObject->new( \%params );
58  
59 3 for my $module ( $tempdir_object->_module_names ) {
60 2 $tempdir_object->_install_module($module);
61 }
62  
63 3 for my $dist ( $tempdir_object->_dist_names ) {
64 1 $tempdir_object->_install_dist($dist);
65 }
66  
67 3 unshift @INC, $tempdir_object->_tempdir->stringify;
68  
69 }
70 5 ▶ if (@imports) {
Branch: 1 branch
BranchTrueFalseTotal
if (@imports) 2 3 5
71 2 $package->export_to_level( 1, undef, @imports );
72 }
73 5 return;
74  
75 }
76  
77 # This code is just to make sure any guard objects
78 # are not lexically visible to the sub they contain creating a self reference.
79 2 ▶sub _mk_clearer {
Subroutine _mk_clearer: called CC=1 SCAR=0.0
80 2 my ($clearee) = @_;
81 2 ▶ return sub { $clearee->clear };
Subroutine __ANON__: called CC=1 SCAR=0.0
82 }
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109 1 ▶sub with_dist_dir {
Subroutine with_dist_dir: called CC=4 SCAR=15.0
Pod documented
110 1 my ( $config, $code ) = @_;
111 1 ▶ if ( 'CODE' ne ( ref $code || q{} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("CODE" ne (ref $code || "")) 0 1 1
Condition50%1/2
ref $code || ''
l!l
10
MC/DC0%0/1
ref $code || ''
ref $code
Truth table50%1/2
A
A= ref $code
Aresult
11
00
112 0 ▶ croak( 'CodeRef expected at end of with_dist_dir(), ' . ( ref $code || qq{scalar="$code"} ) . ' found' );
Condition0%0/2
ref $code || qq[scalar="$code"]
l!l
00
MC/DC0%0/1
ref $code || qq[scalar="$code"]
ref $code
Truth table0%0/2
A
A= ref $code
Aresult
11
00
113 }
114 1 require Test::File::ShareDir::Object::Dist;
115 1 require Scope::Guard;
116 1 my $dist_object = Test::File::ShareDir::Object::Dist->new( extract_dashes( 'dists', $config ) );
117 1 $dist_object->install_all_dists();
118 1 $dist_object->register();
119 1 my $guard = Scope::Guard->new( _mk_clearer($dist_object) ); ## no critic (Variables::ProhibitUnusedVarsStricter)
120 1 return $code->();
121 }
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148 1 ▶sub with_module_dir {
Subroutine with_module_dir: called CC=4 SCAR=15.0
Pod documented
149 1 my ( $config, $code ) = @_;
150 1 ▶ if ( 'CODE' ne ( ref $code || q{} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("CODE" ne (ref $code || "")) 0 1 1
Condition50%1/2
ref $code || ''
l!l
10
MC/DC0%0/1
ref $code || ''
ref $code
Truth table50%1/2
A
A= ref $code
Aresult
11
00
151 0 ▶ croak( 'CodeRef expected at end of with_module_dir(), ' . ( ref $code || qq{scalar="$code"} ) . ' found' );
Condition0%0/2
ref $code || qq[scalar="$code"]
l!l
00
MC/DC0%0/1
ref $code || qq[scalar="$code"]
ref $code
Truth table0%0/2
A
A= ref $code
Aresult
11
00
152 }
153  
154 1 require Test::File::ShareDir::Object::Module;
155 1 require Scope::Guard;
156  
157 1 my $module_object = Test::File::ShareDir::Object::Module->new( extract_dashes( 'modules', $config ) );
158  
159 1 $module_object->install_all_modules();
160 1 $module_object->register();
161 1 my $guard = Scope::Guard->new( _mk_clearer($module_object) ); ## no critic (Variables::ProhibitUnusedVarsStricter)
162  
163 1 return $code->();
164 }
165  
166 6 1;
167  
168 __END__
« lib/Test/File/ShareDir/Utils.pm ↑ Summary lib/Test/File/ShareDir/TempDirObject.pm »