Acme-Devel-Hide-Tiny
view release on metacpan or search on metacpan
"type" : "git",
"url" : "https://github.com/dagolden/Acme-Devel-Hide-Tiny.git",
"web" : "https://github.com/dagolden/Acme-Devel-Hide-Tiny"
}
},
"version" : "0.002",
"x_authority" : "cpan:DAGOLDEN",
"x_contributors" : [
"Graham Knop <haarg@haarg.org>"
],
"x_serialization_backend" : "Cpanel::JSON::XS version 3.0225"
}
NAME
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:
# 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 NAME
Acme::Devel::Hide::Tiny - Hide a perl module for testing, in one statement
=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>.
lib/Acme/Devel/Hide/Tiny.pm view on Meta::CPAN
# 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.
( run in 1.017 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )