Acme-Devel-Hide-Tiny
view release on metacpan or search on metacpan
Acme::Devel::Hide::Tiny - Hide a perl module for testing, in one
statement
VERSION
version 0.002
SYNOPSIS
# in 'foo.t', assume we want to hide Cpanel::JSON::XS
# hide Cpanel::JSON::XS -> Cpanel/JSON/XS.pm
use lib map {
my $m = $_;
sub { return unless $_[1] eq $m; die "Can't locate $_[1] in \@INC (hidden)\n"; }
} qw{Cpanel/JSON/XS.pm};
DESCRIPTION
The Devel::Hide and Test::Without::Module modules are very helpful
development tools. Unfortunately, using them in your .t files adds a
test dependency. Maybe you don't want to do that.
Instead, you can use the one-liner from the SYNOPSIS above, which is an
extremely stripped down version of Devel::Hide.
Here is a more verbose, commented version of it:
# 'lib' adds its arguments to the front of @INC
use lib
# add one coderef per path to hide
map {
# create lexical for module
my $m = $_;
# construct and return a closure that dies for the module path to hide
sub {
# return if not the path to hide; perl checks rest of @INC
return unless $_[1] eq $m;
# die with the error message we want
die "Can't locate $_[1] in \@INC (hidden)\n";
}
}
# input to map is a list module names, converted to paths;
qw{Cpanel/JSON/XS.pm JSON/XS.pm}
; # end of 'use lib' statement
When perl sees a coderef in @INC, it gives the coderef a chance to
provide the source code of that module. In this case, if the path is the
one we want to hide, it dies with the message we want and perl won't
continue looking at @INC to find the real module source. The module is
hidden and dies with a message similar to the one that would happen if
it weren't installed.
lib/Acme/Devel/Hide/Tiny.pm view on Meta::CPAN
=head1 VERSION
version 0.002
=head1 SYNOPSIS
# in 'foo.t', assume we want to hide Cpanel::JSON::XS
# hide Cpanel::JSON::XS -> Cpanel/JSON/XS.pm
use lib map {
my $m = $_;
sub { return unless $_[1] eq $m; die "Can't locate $_[1] in \@INC (hidden)\n"; }
} qw{Cpanel/JSON/XS.pm};
=head1 DESCRIPTION
The L<Devel::Hide> and L<Test::Without::Module> modules are very helpful
development tools. Unfortunately, using them in your F<.t> files adds a
test dependency. Maybe you don't want to do that.
Instead, you can use the one-liner from the SYNOPSIS above, which is an
extremely stripped down version of L<Devel::Hide>.
Here is a more verbose, commented version of it:
# 'lib' adds its arguments to the front of @INC
use lib
# add one coderef per path to hide
map {
# create lexical for module
my $m = $_;
# construct and return a closure that dies for the module path to hide
sub {
# return if not the path to hide; perl checks rest of @INC
return unless $_[1] eq $m;
# die with the error message we want
die "Can't locate $_[1] in \@INC (hidden)\n";
}
}
# input to map is a list module names, converted to paths;
qw{Cpanel/JSON/XS.pm JSON/XS.pm}
; # end of 'use lib' statement
When perl sees a coderef in C<@INC>, it gives the coderef a chance to
provide the source code of that module. In this case, if the path is the
one we want to hide, it dies with the message we want and perl won't
continue looking at C<@INC> to find the real module source. The module is
hidden and dies with a message similar to the one that would happen if it
weren't installed.
t/00-report-prereqs.t view on Meta::CPAN
if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) {
push @dep_errors, "$mod is not installed ($req_string)";
}
}
}
if ( @reports ) {
push @full_reports, "=== $title ===\n\n";
my $ml = _max( map { length $_->[0] } @reports );
my $wl = _max( map { length $_->[1] } @reports );
my $hl = _max( map { length $_->[2] } @reports );
if ($type eq 'modules') {
splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl];
push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports;
}
else {
splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl];
push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports;
}
push @full_reports, "\n";
}
}
}
if ( @full_reports ) {
diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports;
}
xt/author/00-compile.t view on Meta::CPAN
use IO::Handle;
open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";
my @warnings;
for my $lib (@module_files)
{
# see L<perlfaq8/How can I capture STDERR from an external command?>
my $stderr = IO::Handle->new;
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
$^X, @switches, '-e', "require q[$lib]"))
if $ENV{PERL_COMPILE_TEST_DEBUG};
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$lib loaded ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
( run in 1.719 second using v1.01-cache-2.11-cpan-49f99fa48dc )