1Test::Module::Used(3) User Contributed Perl DocumentationTest::Module::Used(3)
2
3
4

NAME

6       Test::Module::Used - Test required module is really used and vice versa
7       between lib/t and META.yml
8

SYNOPSIS

10         #!/usr/bin/perl -w
11         use strict;
12         use warnings;
13         use Test::Module::Used;
14         my $used = Test::Module::Used->new();
15         $used->ok;
16

DESCRIPTION

18       Test dependency between module and META.yml.
19
20       This module reads META.yml and get build_requires and requires. It
21       compares required module is really used and used module is really
22       required.
23

Important changes

25       Some behavior changed since 0.1.3_01.
26
27       •   perl_version set in constructor is prior to use, and read version
28           from META.yml(not read from use statement in *.pm)
29
30       •   deprecated interfaces are deleted. (module_dir, test_module_dir,
31           exclude_in_moduledir and push_exclude_in_moduledir)
32

methods

34   new
35       create new instance
36
37       all parameters are passed by hash-style, and optional.
38
39       in ordinary use.
40
41         my $used = Test::Module::Used->new();
42         $used->ok();
43
44       all parameters are as follows.(specified values are default, except
45       exclude_in_testdir)
46
47         my $used = Test::Module::Used->new(
48           test_dir     => ['t'],            # directory(ies) which contains test scripts.
49           lib_dir      => ['lib'],          # directory(ies) which contains module libs.
50           test_lib_dir => ['t'],            # directory(ies) which contains libs used ONLY in test (ex. MockObject for test)
51           meta_file    => 'META.json' or
52                           'META.yml' or
53                           'META.yaml',      # META file (YAML or JSON which contains module requirement information)
54           perl_version => '5.008',          # expected perl version which is used for ignore core-modules in testing
55           exclude_in_testdir => [],         # ignored module(s) for test even if it is used.
56           exclude_in_libdir   => [],        # ignored module(s) for your lib even if it is used.
57           exclude_in_build_requires => [],  # ignored module(s) even if it is written in build_requires of META.yml.
58           exclude_in_requires => [],        # ignored module(s) even if it is written in requires of META.yml.
59         );
60
61       if perl_version is not passed in constructor, this modules reads
62       meta_file and get perl version.
63
64       exclude_in_testdir is automatically set by default. This module reads
65       lib_dir and parse "package" statement, then found "package" statements
66       and myself(Test::Module::Used) is set.  exclude_in_libdir is also
67       automatically set by default. This module reads lib_dir and parse
68       "package" statement, found "package" statement are
69       set.(Test::Module::Used isn't included)
70
71   ok()
72       check used modules are required in META file and required modules in
73       META files are used.
74
75         my $used = Test::Module::Used->new(
76           exclude_in_testdir => ['Test::Module::Used', 'My::Module'],
77         );
78         $used->ok;
79
80       First, This module reads META.yml and get build_requires and requires.
81       Next, reads module directory (by default lib) and test directory(by
82       default t), and compare required module is really used and used module
83       is really required. If all these requirement information is OK, test
84       will success.
85
86       It is NOT allowed to call ok(), used_ok() and requires_ok() in same
87       test file.
88
89   used_ok()
90       Only check used modules are required in META file.  Test will success
91       if unused requires or build_requires are defined.
92
93         my $used = Test::Module::Used->new();
94         $used->used_ok;
95
96       It is NOT allowed to call ok(), used_ok() and requires_ok() in same
97       test file.
98
99   requires_ok()
100       Only check required modules in META file is used.  Test will success if
101       used modules are not defined in META file.
102
103         my $used = Test::Module::Used->new();
104         $used->requires_ok;
105
106       It is NOT allowed to call ok(), used_ok() and requires_ok() in same
107       test file.
108
109   push_exclude_in_libdir( @exclude_module_names )
110       add ignored module(s) for your module(lib) even if it is used after
111       new()'ed.  this is usable if you want to use auto set feature for
112       exclude_in_libdir but manually specify exclude modules.
113
114       For example,
115
116        my $used = Test::Module::Used->new(); #automatically set exclude_in_libdir
117        $used->push_exclude_in_libdir( qw(Some::Module::Which::You::Want::To::Exclude) );#module(s) which you want to exclude
118        $used->ok(); #do test
119
120   push_exclude_in_testdir( @exclude_module_names )
121       add ignored module(s) for test even if it is used after new()'ed.  this
122       is usable if you want to use auto set feature for exclude_in_testdir
123       but manually specify exclude modules.
124
125       For example,
126
127        my $used = Test::Module::Used->new(); #automatically set exclude_in_testdir
128        $used->push_exclude_in_testdir( qw(Some::Module::Which::You::Want::To::Exclude) );#module(s) which you want to exclude
129        $used->ok(); #do test
130

AUTHOR

132       Takuya Tsuchida <tsucchi@cpan.org>
133

SEE ALSO

135       Test::Dependencies has almost same feature.
136

REPOSITORY

138       <http://github.com/tsucchi/Test-Module-Used>
139
141       Copyright (c) 2008-2014 Takuya Tsuchida
142
143       This library is free software; you can redistribute it and/or modify it
144       under the same terms as Perl itself.
145
146
147
148perl v5.36.0                      2022-07-22             Test::Module::Used(3)
Impressum