1 package VPIT::TestHelpers;
7 load_or_skip => \&load_or_skip,
8 skip_all => \&skip_all,
13 while (my ($name, $code) = each %exports) {
15 *{$pkg.'::'.$name} = $code;
22 if ($INC{'Test/Leaner.pm'}) {
23 $stash = \%Test::Leaner::;
26 $stash = \%Test::More::;
28 my $glob = $stash->{$sub};
29 return $glob ? *$glob{CODE} : undef;
32 sub skip_all { $test_sub->('plan')->(skip_all => $_[0]) }
35 my $diag = $test_sub->('diag');
43 my ($pkg, $ver, $imports, $desc) = @_;
44 my $spec = $ver && $ver !~ /^[0._]*$/ ? "$pkg $ver" : $pkg;
46 if (eval "use $spec (); 1") {
47 $ver = do { no strict 'refs'; ${"${pkg}::VERSION"} };
48 $ver = 'undef' unless defined $ver;
50 my @imports = @$imports;
51 my $caller = (caller 0)[0];
53 my $res = eval <<"IMPORTER";
56 BEGIN { \$pkg->import(\@imports) }
59 skip_all "Could not import '@imports' from $pkg $ver: $@" unless $res;
61 diag "Using $pkg $ver";
63 (my $file = "$pkg.pm") =~ s{::}{/}g;
65 skip_all "$spec $desc";
69 package VPIT::TestHelpers::Guard;
72 my ($class, $code) = @_;
74 bless { code => $code }, $class;
77 sub DESTROY { $_[0]->{code}->() }