File Coverage

blib/lib/Test2/Tools/Target.pm
Criterion Covered Total %
statement 39 42 92.8
branch 5 8 62.5
condition 1 2 50.0
subroutine 7 8 87.5
pod 0 1 0.0
total 52 61 85.2


line stmt bran cond sub pod time code
1             package Test2::Tools::Target;
2 156     156   1588 use strict;
  156         317  
  156         4640  
3 156     156   780 use warnings;
  156         291  
  156         6539  
4              
5             our $VERSION = '0.000156';
6              
7 156     156   922 use Carp qw/croak/;
  156         364  
  156         7443  
8              
9 156     156   1077 use Test2::Util qw/pkg_to_file/;
  156         402  
  156         41233  
10              
11             sub import {
12 3     3   40 my $class = shift;
13              
14 3         8 my $caller = caller;
15 3         14 $class->import_into($caller, @_);
16             }
17              
18             sub import_into {
19 69     69 0 210 my $class = shift;
20 69 50       326 my $into = shift or croak "no destination package provided";
21              
22 69 50       307 croak "No targets specified" unless @_;
23              
24 69         173 my %targets;
25 69 100       325 if (@_ == 1) {
26 68 50       399 if (ref $_[0] eq 'HASH') {
27 0         0 %targets = %{ $_[0] };
  0         0  
28             }
29             else {
30 68         380 ($targets{CLASS}) = @_;
31             }
32             }
33             else {
34 1         4 %targets = @_;
35             }
36              
37 69         385 for my $name (keys %targets) {
38 69         219 my $target = $targets{$name};
39              
40 69         1703 my $file = pkg_to_file($target);
41 69         15940 require $file;
42              
43 69   50     394 $name ||= 'CLASS';
44              
45 69         174 my $const;
46             {
47 69         179 my $const_target = "$target";
  69         236  
48 69     0   834 $const = sub() { $const_target };
  0         0  
49             }
50              
51 156     156   1227 no strict 'refs';
  156         361  
  156         17421  
52 69         268 *{"$into\::$name"} = \$target;
  69         525  
53 69         226 *{"$into\::$name"} = $const;
  69         2506  
54             }
55             }
56              
57             1;
58              
59             __END__