Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexically Require Module #36

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions ppcs/ppc0023-lexical-require.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@ use feature 'lexical_require`;
use Some::Module;
```

With the above, code outside of the above scope cannot see `Some::Module` unless
it explicitly requires it.
Within a given lexical scope, **ß**, if the 'lexical_require' feature is used,
code outside of scope **ß** cannot call methods against class names that have

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ovid note this needs to be changed. You cant have a feature used in a given scope affect code in a totally different unrelated scope. (As discussed elsewhere.)

not been explicitly required within the current package, and doing so would
throw an exception. Methods would be allowed against any object (blessed
reference), but not against a class.

Note: that doesn't mean the transitive dependencies aren't available. If
scope **ß** uses `lexical_require` and `Hash::Ordered`, but scope **∂** uses
`Hash::Ordered` but _doesn't_ use `lexical_require`, then `Hash::Ordered` is
still available to everyone as a transitive dependency. However, individual module
authors will still have greater safety in knowing that people are not directly
relying on their internals.

## Motivation

Expand Down Expand Up @@ -70,6 +80,14 @@ my $object = Some::Class->new; # succeeds if `Some::Class` has a `new` method
my $cache = Hash::Ordered->new; # fails
```

Note that, if possible, this should also apply to package variables. In the
above, `$Hash::Ordered::VERSION` should fail. This is again, to prevent
accidentally relying on code that might not be there. If `Foo` switches from
`Hash::Ordered` to a similar module, all code relying on `Hash::Ordered` as a
transitive dependency would break. As a module author, I don't want to break
someone else's code just because I changed internal details that they should
not know about.

## Backwards Compatibility

This feature should be 100% backwards compatible for new code. If retrofitted
Expand Down