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
24       a 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 need not
45       be written explicitly.  It can be used directly, but it is intended to
46       be invoked from the "import" method of a Modern::Perl-style module that
47       enables modern Perl features and conveniences and cleans up legacy Perl
48       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   EXPORT
89       None by default.
90

NOTES

92       Because some versions of YAML::XS may interpret the key of "true" as a
93       boolean, you may have trouble declaring a dependency on true.pm.  You
94       can work around this by declaring a dependency on the package
95       true::VERSION, which has the same version as true.pm.
96

SEE ALSO

98       ·   latest
99
100       ·   Modern::Perl
101
102       ·   nonsense
103
104       ·   perl5i
105
106       ·   Toolkit
107
108       ·   uni::perl
109

AUTHOR

111       chocolateboy, <chocolate@cpan.org>
112
114       Copyright (C) 2010-2011 by chocolateboy
115
116       This library is free software; you can redistribute it and/or modify it
117       under the same terms as Perl itself, either Perl version 5.10.0 or, at
118       your option, any later version of Perl 5 you may have available.
119
120
121
122perl v5.28.0                      2011-04-18                           true(3)
Impressum