diff --git a/pod/perlclass.pod b/pod/perlclass.pod index be67f5622784..aa69f9b2bb27 100644 --- a/pod/perlclass.pod +++ b/pod/perlclass.pod @@ -185,6 +185,26 @@ Just like regular subroutines, methods I be anonymous: } } +Methods can also be declared as lexical subroutines, using the C prefix. +This creates a subroutine that is lexically visible within the current scope, +but does not appear in the symbol table. The effect is that of a I +method; one that can be called from within the class's own code, but not from +outside. + +At present, there is no special syntax for invoking a lexical method, so for +now they must be called as if they are regular (lexical) subroutines, +remembering to pass the C<$self> invocant as the first positional argument. + + class LexicalMethod { + my method abc ($x, $y) { + say "Internal method abc invoked with x=$x y=$y"; + } + + method xyz { + abc($self, "x", "y"); + } + } + =head1 ATTRIBUTES Specific aspects of the keywords mentioned above are managed using diff --git a/pod/perldelta.pod b/pod/perldelta.pod index e0c3a7a72c16..232834a2cdd1 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -27,6 +27,12 @@ here, but most should go in the L section. [ List each enhancement as a =head2 entry ] +=head2 Lexical method syntax using C + +Like C since Perl version 5.18, C can now be prefixed with the +C keyword. This declares a subroutine that has lexical, rather than +package visibility. See L for more detail. + =head1 Security XXX Any security-related notices go here. In particular, any security