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

A meta-method example in the mop page seems incorrect #847

Closed
titsuki opened this issue Aug 20, 2016 · 2 comments
Closed

A meta-method example in the mop page seems incorrect #847

titsuki opened this issue Aug 20, 2016 · 2 comments
Labels
docs Documentation issue (primary issue type)

Comments

@titsuki
Copy link
Member

titsuki commented Aug 20, 2016

I received an error message, when I ran the following example code.

  • Example code
    #| THIS IS A CLASS FOR SHOUTING THINGS
    class MY-CLASSES-ARE-ALL-CAPS {
        method WHY { "I DON'T KNOW" }
    }
    my $c = MY-CLASSES-ARE-ALL-CAPS.new;

(From https://docs.perl6.org/language/mop#Metamethods)

  • Error message
Method '_add_leading' not found for invocant of class 'Str'

However, I'm not sure what the better one is.

@titsuki titsuki changed the title An meta-method example in the mop page seems incorrect A meta-method example in the mop page seems incorrect Aug 20, 2016
@titsuki titsuki added the docs Documentation issue (primary issue type) label Aug 20, 2016
@jonathanstowe
Copy link
Contributor

I'm not sure whether the assertion in that whole section is true. The error is precisely because the explicitly defined WHY method is being called in the SET_LEADING_DOCS method which in turn expects the WHY to return a Pod::Block::Declarator object (which has the _add_leading method.)

I would say that it's remove the assertion about the quotes and the example completely. Unless anyone feels it is a bug that the behaviour doesn't match the doc of course.

@jonathanstowe
Copy link
Contributor

The example will run if it is rewritten so that the over-ride WHY returns the right kind of this:

#| THIS IS A CLASS FOR SHOUTING THINGS
class MY-CLASSES-ARE-ALL-CAPS {
    multi method WHY { Pod::Block::Declarator.new(leading => ["I DON'T KNOW"]) }
}
my $c = MY-CLASSES-ARE-ALL-CAPS.new;
say $c.WHY;    
say $c."WHY"(); 

However it doesn't do what the text says because the over-ridden version will always get called.

I think that it definitely is remove the last sentence of the text and the example. Unless anyone chimes in quickly I'll just do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type)
Projects
None yet
Development

No branches or pull requests

2 participants