1true(3)               User Contributed Perl Documentation              true(3)
2
3
4

NAME

6       true - automatically return a true value when a file is required
7

SYNOPSIS

9         package Contemporary::Perl;
10
11         use strict;
12         use warnings;
13         use true;
14
15         sub import {
16             strict->import();
17             warnings->import();
18             true->import();
19         }
20

DESCRIPTION

22       Perl's "require" builtin (and its "use" wrapper) requires the files it
23       loads to return a true value. This is usually accomplished by placing a
24       single
25
26           1;
27
28       statement at the end of included scripts or modules. It's not onerous
29       to add but it's a speed bump on the Perl novice's road to
30       enlightenment. In addition, it appears to be a non-sequitur to the
31       uninitiated, leading some to attempt to mitigate its appearance with a
32       comment:
33
34           1; # keep require happy
35
36       or:
37
38           1; # Do not remove this line
39
40       or even:
41
42           1; # Must end with this, because Perl is bogus.
43
44       This module packages this "return true" behaviour so that it doesn't
45       need to be written explicitly. It can be used directly, but it is
46       intended to be invoked from the "import" method of a Modern::Perl-style
47       module that enables modern Perl features and conveniences and cleans up
48       legacy Perl warts.
49
50   METHODS
51       "true" is file-scoped rather than lexically-scoped. Importing it
52       anywhere in a file (e.g. at the top-level or in a nested scope) causes
53       that file to return true, and unimporting it anywhere in a file
54       restores the default behaviour. Redundant imports/unimports are
55       ignored.
56
57       import
58
59       Enable the "automatically return true" behaviour for the currently-
60       compiling file. This should typically be invoked from the "import"
61       method of a module that loads "true". Code that uses this module solely
62       on behalf of its callers can load "true" without importing it e.g.
63
64           use true (); # don't import
65
66           sub import {
67               true->import();
68           }
69
70           1;
71
72       But there's nothing stopping a wrapper module also importing "true" to
73       obviate its own need to explicitly return a true value:
74
75           use true; # both load and import it
76
77           sub import {
78               true->import();
79           }
80
81           # no need to return true
82
83       unimport
84
85       Disable the "automatically return true" behaviour for the currently-
86       compiling file.
87
88   EXPORTS
89       None by default.
90

NOTES

92       Because the unquoted name "true" represents the boolean value "true" in
93       YAML, the module name must be quoted when written as a dependency in
94       META.yml. In cases where this can't easily be done, a dependency can be
95       declared on the package true::VERSION, which has the same version as
96       "true.pm".
97

VERSION

99       1.0.2
100

SEE ALSO

102       •   latest
103
104       •   Modern::Perl
105
106       •   nonsense
107
108       •   perl5i
109
110       •   Toolkit
111

AUTHOR

113       chocolateboy <chocolate@cpan.org>
114
116       Copyright (c) 2010-2020 by chocolateboy.
117
118       This library is free software; you can redistribute it and/or modify it
119       under the terms of the Artistic License 2.0
120       <https://www.opensource.org/licenses/artistic-license-2.0.php>.
121
122
123
124perl v5.38.0                      2023-07-21                           true(3)
Impressum