File Coverage

inc/My/Module/Test.pm
Criterion Covered Total %
statement 30 30 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 1 2 50.0
total 41 42 97.6


line stmt bran cond sub pod time code
1             package My::Module::Test;
2              
3 6     6   116 use 5.008001;
  6         22  
4              
5 6     6   30 use strict;
  6         11  
  6         127  
6 6     6   24 use warnings;
  6         37  
  6         321  
7              
8 6     6   30 use Carp qw{ croak };
  6         39  
  6         460  
9 6     6   33 use Exporter qw{ import };
  6         9  
  6         190  
10 6     6   49 use Test2::V0;
  6         10  
  6         107  
11 6     6   12223 use Test2::Util qw{ pkg_to_file };
  6         8  
  6         921  
12              
13             our $VERSION = '0.009';
14              
15             our @EXPORT_OK = qw{
16             build_skip_reason
17             cant_locate
18             CHECK_MISSING_INFO
19             $LOAD_ERROR_TEMPLATE
20             };
21              
22             # NOTE that if there are no diagnostics, info() returns undef, not an
23             # empty array. I find this nowhere documented, so I am checking for
24             # both.
25 6     6   91 use constant CHECK_MISSING_INFO => in_set( undef, array{ end; } );
  6         39  
  6         95  
  6         832  
26              
27             {
28             # We jump through these hoops because we do not want to have the
29             # test routines assume that the module under test can be loaded.
30              
31             my $code = eval {
32             require Test2::Tools::LoadModule;
33             Test2::Tools::LoadModule->can( '__build_load_eval' );
34             };
35              
36             sub build_skip_reason {
37 7     7 0 2993 my @arg = @_;
38 7         26 return sprintf 'Unable to %s', $code->( @arg );
39             }
40             }
41              
42             our $LOAD_ERROR_TEMPLATE = '%s';
43              
44             sub cant_locate {
45 4     4 1 1629 my ( $module ) = @_;
46 4         18 my $fn = pkg_to_file( $module );
47 4         65 my $msg = sprintf $LOAD_ERROR_TEMPLATE, "Can't locate $fn in \@INC";
48 4         138 return match qr/ \A \Q$msg\E \b /smx;
49             }
50              
51             1;
52              
53             __END__
54              
55             =head1 NAME
56              
57             My::Module::Test - Test support for Test2::Tools::LoadModule
58              
59             =head1 SYNOPSIS
60              
61             use lib qw{ inc };
62             use My::Module::Test qw{
63             -inc
64             cant_locate
65             CHECK_MISSING_INFO
66             };
67              
68             =head1 DESCRIPTION
69              
70             This module is B<private> to the C<Test2-Tools-LoadModule>
71             distribution. It can be changed or revoked without notice. Documentation
72             is for the benefit of the author only.
73              
74             This module provides test support for the C<Test2-Tools-LoadModule>
75             distribution.
76              
77             =head1 EXPORTS
78              
79             This module exports nothing by default. Yes, I intend to use everything,
80             but there aren't many things here and if I import them explicitly it
81             documents what came from this module.
82              
83             The following things are available for export:
84              
85             =head2 -inc
86              
87             This option causes a code reference to be prepended to C<@INC>. This
88             code reference examines the call stack, and if it finds
89             L<Test2::Tools::LoadModule|Test2::Tools::LoadModule> returns the
90             requested file from F<t/lib/>, or an error if the file is not found. If
91             L<Test2::Tools::LoadModule|Test2::Tools::LoadModule> is not found
92             on the call stack, nothing is returned, which causes Perl's normal
93             module-loading machinery to be invoked.
94              
95             =head2 cant_locate
96              
97             This subroutine takes as its argument a module name and returns a
98             L<Test2::V0|Test2::V0> C<match> which matches the message generated by
99             Perl if the module can not be located.
100              
101             =head2 CHECK_MISSING_INFO
102              
103             This manifest constant returns a L<Test2::V0|Test2::V0> check which
104             passes if the checked quantity is either C<undef> or a reference to an
105             empty array. This is intended to be used to check the C<info> field of
106             an event, since I find nowhere documented what this is if there is no
107             info.
108              
109             =head1 SEE ALSO
110              
111             L<Test2::V0|Test2::V0>
112              
113             =head1 SUPPORT
114              
115             This module is unsupported in the usual sense, but if you think it is
116             causing test failures, please file a bug report at
117             L<https://rt.cpan.org/Public/Dist/Display.html?Name=Test2-Tools-LoadModule>,
118             L<https://github.com/trwyant/perl-Test2-Tools-LoadModule/issues>, or in
119             electronic mail to the author.
120              
121             =head1 AUTHOR
122              
123             Thomas R. Wyant, III F<wyant at cpan dot org>
124              
125             =head1 COPYRIGHT AND LICENSE
126              
127             Copyright (C) 2020-2026 by Thomas R. Wyant, III
128              
129             This program is free software; you can redistribute it and/or modify it
130             under the same terms as Perl 5.10.0. For more details, see the full text
131             of the licenses in the files F<LICENSE-Artistic> and F<LICENSE-GPL>.
132              
133             This program is distributed in the hope that it will be useful, but
134             without any warranty; without even the implied warranty of
135             merchantability or fitness for a particular purpose.
136              
137             =cut
138              
139             # ex: set textwidth=72 :