Skip to content

Should custom accessors be called for constructor args? #23

Description

If someone has custom accessors with coercion, currently the accessor won't
be called and the coercion thus won't be applied to constructor arguments,
which are directly blessed into the object hash.

Should they be called if we can detect custom accessors? If not, we should
document a pattern to help people do this, such as in BUILD:

sub BUILD {
    my $self = shift;

    $self->$_( $self->{$_} ) for qw/baz bam/; # coerce custom
}

I worry that there's no way to know that a custom accessor is also a
mutator, so leaving it to the end user in BUILD might be the safest thing.

CC: @miyagawa

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions