10
10
## Abstract
11
11
12
12
This RFC proposes a ` yield_true ` feature. When used, the current Perl _ file_
13
- containing ` use feature 'yield_true'l ` will automatically return a true value
14
- after successful compilation, eliminating the neeed for a "1" (or other true
13
+ containing ` use feature 'yield_true'; ` will automatically return a true value
14
+ after successful compilation, eliminating the need for a "1" (or other true
15
15
value) at the end of the file.
16
16
17
17
## Motivation
@@ -26,13 +26,18 @@ _doesn't_ end with a true value but nonetheless compiles just fine because
26
26
_ something_ in the code returned a true value and the code compiles as a
27
27
side-effect.
28
28
29
-
30
29
## Specification
31
30
32
31
use feature 'yield_true';
33
32
34
33
Code using the above does not need to return a magic true value when compiled.
35
34
35
+ If the module explicitly returns a false value, we should consider if this can
36
+ be ignored (I suspect this is usually a bug). However, the module author
37
+ _ might_ have conditional logic to explicitly return a false value in case
38
+ there's a missing dependency (or for some other reason). Discussion might be
39
+ useful here.
40
+
36
41
## Backwards Compatibility
37
42
38
43
There are no compatibility concerns I'm aware of.
@@ -47,19 +52,50 @@ None. See above.
47
52
48
53
## Prototype Implementation
49
54
50
- None .
55
+ There is a prototype implementation at [ true ] ( https://metacpan.org/pod/true ) .
51
56
52
57
## Future Scope
53
58
54
- I believe this is complete.
59
+ Due to this being a named feature, this can eventually be the default behavior
60
+ when ` use v5.XX; ` is used.
55
61
56
62
## Rejected Ideas
57
63
58
- None that I'm aware of.
64
+ It's been discussed that we should return the package name instead. This
65
+ supports:
66
+
67
+ my $obj = (require Some::Object::Class)->new;
68
+
69
+ However, per haarg:
70
+
71
+ > Changing the return value of require seems like a separate issue from what
72
+ > this RFC wants to address.
73
+ >
74
+ > If you wanted require to always return the same value, and for that value to
75
+ > come from the file, you need a new location to store these values. This
76
+ > would probably mean a new superglobal to go along with %INC. And it would
77
+ > usually be useless because most modules return 1. I don't think this is a
78
+ > very good idea.
79
+ >
80
+ > If you wanted require to always return the package name, it's a separate
81
+ > issue from this RFC because that means ignoring the return value from the
82
+ > file. It also presents a problem because require doesn't actually take
83
+ > package names. It takes file path fragments. Foo::Bar is translated to
84
+ > "Foo/Bar.pm" at parse time. This would then need to be converted back to a
85
+ > package name, or do something else. I don't think this is a good idea
86
+ > either.
87
+ >
88
+ > Instead, it's probably best addressed with a builtin::load or similar
89
+ > routine that accepts a package as a string. This has been discussed in the
90
+ > past, and solves other problems. Module::Runtime has a use_module function
91
+ > that behaves like this, returning the package name.
92
+
93
+ Thus, we prefer simply returning ` true ` (or ` 1 ` ).
59
94
60
95
## Open Issues
61
96
62
- None that I'm aware of.
97
+ * Should returning a false value be ignored?
98
+ * Should any explicit return be an error?
63
99
64
100
## Copyright
65
101
0 commit comments