Skip to content

Corinna classes with the overload pragma #109

Answered by HaraldJoerg
lschierer asked this question in Q&A
Discussion options

You must be logged in to vote

It Just Works.

There are a few caveats when using the new syntax:

  • The method keyword automatically enables signatures. If you use them, keep in mind that all overloaded methods (even unary ones) are called with three parameters. This is the same as with feature 'signatures' in old style classes, though.
  • The encapsulation of values makes it necessary to make the fields you need for e.g. a comparison available via methods. This is different from both hashref-based classes and different from inside-out classes built with Class::Std. Here's a trivial example:
use feature 'class';
no warnings 'experimental';

class V {
    use overload
	'-'   => '_neg',
	'<=>' => '_compare',
	;

    field $x

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lschierer
Comment options

Answer selected by lschierer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants