Skip to content

Commit 1a751fb

Browse files
committed
RFC 0018: add some examples
1 parent b8be021 commit 1a751fb

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

rfcs/rfcOVID-0018.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,40 @@ None expected.
4848

4949
## Examples
5050

51-
None. See above.
51+
Imagine this module:
52+
53+
```perl
54+
package Demo1;
55+
use feature 'module_true';
56+
57+
sub import {
58+
warn "You imported a module!\n";
59+
}
60+
```
61+
62+
When loaded by `require` or `use` anywhere in perl, this would import
63+
successfully, despite the lack of a true value at the end.
64+
65+
This module shows an (almost certainly never useful) way to croak anyway:
66+
67+
```perl
68+
package Demo2;
69+
use feature 'module_true';
70+
71+
return 1 if $main::test_1;
72+
return 0 if $main::test_2;
73+
74+
{
75+
no feature 'module_true';
76+
return 0 if $main::test_3;
77+
}
78+
```
79+
80+
In this example, the only case in which requiring Demo2 would fail is if
81+
`$main::test_3` was true. The previous `return 0 if $main::test_2` would still
82+
be within the scope of the `module_true` feature, so the return value would be
83+
ignored. When `0` is returned outside the effect of `module_true`, though, the
84+
old behavior of testing the return value is back in effect.
5285

5386
## Prototype Implementation
5487

0 commit comments

Comments
 (0)