File Coverage

blib/lib/Require/HookChain/test/random_fail.pm
Criterion Covered Total %
statement 0 8 0.0
branch 0 4 0.0
condition n/a
subroutine 0 2 0.0
pod 0 2 0.0
total 0 16 0.0


line stmt bran cond sub pod time code
1             ## no critic: TestingAndDebugging::RequireUseStrict
2             package Require::HookChain::test::random_fail;
3              
4             # IFUNBUILT
5             # use strict;
6             # use warnings;
7             # END IFUNBUILT
8              
9             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10             our $DATE = '2023-12-05'; # DATE
11             our $DIST = 'Require-HookChain'; # DIST
12             our $VERSION = '0.016'; # VERSION
13              
14             sub new {
15 0     0 0   my ($class, $probability) = @_;
16 0 0         $probability = 0.5 unless defined $probability;
17 0           bless {probability=>$probability}, $class;
18             }
19              
20             sub Require::HookChain::test::random_fail::INC {
21 0     0 0   my ($self, $r) = @_;
22              
23 0 0         if (rand() < $self->{probability}) {
24 0           my $filename = $r->filename;
25 0           die "Can't locate $filename: test::random_fail";
26             }
27 0           ();
28             }
29              
30             1;
31             # ABSTRACT: Fail a module loading randomly
32              
33             __END__