Skip to content

Commit

Permalink
Add some docs and perldelta
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Jan 24, 2025
1 parent 8aa2b61 commit 783f61c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pod/perlclass.pod
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,26 @@ Just like regular subroutines, methods I<can> be anonymous:
}
}

Methods can also be declared as lexical subroutines, using the C<my> 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<private>
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
Expand Down
6 changes: 6 additions & 0 deletions pod/perldelta.pod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ here, but most should go in the L</Performance Enhancements> section.

[ List each enhancement as a =head2 entry ]

=head2 Lexical method syntax using C<my method>

Like C<sub> since Perl version 5.18, C<method> can now be prefixed with the
C<my> keyword. This declares a subroutine that has lexical, rather than
package visibility. See L<perlclass> for more detail.

=head1 Security

XXX Any security-related notices go here. In particular, any security
Expand Down

0 comments on commit 783f61c

Please sign in to comment.