It is very easy to implement Class::MOP::Instance's inline_[sg]et_slot_value functions in terms of inline_slot_access, but very hard to do the reverse; because of this, it seems to me that Moose::Meta::Method::Accessor should always use the more specific, easier to implement variant. Right now, the implementations of read/write accessors and lazy attributes both use inline_slot_access in fairly easy to eliminate ways; is this a bug?
If so, should code outside subclasses of Class::MOP::Instance be using inline_slot_access at all? For context and clarification, here is a mockup of what I'm currently trying to do. This file fails to compile at the end when it attempts to inline an accessor for a lazy attribute, and so uses inline_slot_access in a non-essential way. -sorear #! /usr/bin/perl package SomeAwesomeDB; sub new_row { } sub read { } sub write { } package MooseX::SomeAwesomeDBFields; use Moose::Role; sub inline_create_instance { my ($self, $classvar) = @_; "bless SomeAwesomeDB::new_row(), $classvar"; } sub inline_get_slot_value { my ($self, $invar, $slot) = @_; "SomeAwesomeDB::read($invar, \"$slot\")"; } sub inline_set_slot_value { my ($self, $invar, $slot, $valexp) = @_; "SomeAwesomeDB::write($invar, \"$slot\", $valexp)"; } sub inline_slot_access { die "SomeAwesomeDB fields are not lvalues, do you expect to tie them?"; } # implementation of methods not called in the example deliberately # omitted package Toy; use Moose; use Moose::Util::MetaRole; Moose::Util::MetaRole::apply_metaclass_roles (for_class => __PACKAGE__, instance_metaclass_roles => [ 'MooseX::SomeAwesomeDBFields' ]); has breaker => ( is => 'ro', isa => 'bool', lazy => 1, default => sub { 0 }, ); __PACKAGE__->meta->make_immutable;
signature.asc
Description: Digital signature