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

better way of accessing attributes in mop-created methods #152

Open
doy opened this issue Nov 18, 2013 · 0 comments
Open

better way of accessing attributes in mop-created methods #152

doy opened this issue Nov 18, 2013 · 0 comments

Comments

@doy
Copy link
Collaborator

doy commented Nov 18, 2013

Right now, to create an accessor using the mop, you need to do something like

    $meta->add_method(
        $meta->method_class->new(
            name => $attr->key_name,
            body => sub {
                my $self = shift;
                $attr->fetch_data_in_slot_for($self);
            }
        )
    );

which is going to be noticeably slower than a handwritten method like method foo { $!foo } since it has to go through the mop for every attribute access, whereas slot access is cached when accessing attributes via twigil variables. We should figure out a way around this, maybe providing an attribute($self, '$!foo') keyword or something along those lines, which would compile down to something more like the actual twigil access. In the core, we may be able to get away with using actual twigils here too, but our current twigil implementation depends on being able to compile the surrounding method ourselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant