Moose icon indicating copy to clipboard operation
Moose copied to clipboard

Let people clear the default value of an attribute when inheriting

Open skington opened this issue 5 years ago • 0 comments

When attempting to fix MooseX::LazyRequire so you can turn it on and off in a sub-class, I came up against the problem that when you inherit from a parent class's attribute, you can't delete an existing key; you can only replace it.

And no, replacing an existing default value with undef isn't the same as there being no default, in the same way that any Moose object's attribute having the explicit value undef is different from it not having a value at all. I remember seeing documentation that claimed that somewhere, but unfortunately I haven't been able to track that down since I realised its mistake.

I appreciate that the note to contributors says (I paraphrase) "we won't add any new features; please consider a MooseX module instead". I tried going down the MooseX route when patching MooseX::LazyRequire, but the problem seems to be a bit too deep in the guts of Moose for that?

I've tried to adhere to existing standards when it comes to exceptions, but I'll confess I haven't gone through every single exception in detail. Similarly, I've tried to match the coding style, but this is a new codebase to me so I'm sure there are things I've missed.

I haven't considered which other attributes of an attribute you might want to clear like this, on top of default. I don't even know if there are any attributes like default, where you have a tripartite value of defined / undefined / non-existent. OTOH, it's a commonplace that the best software is that which is used for a purpose that its authors didn't intend.

skington avatar Jun 19 '20 23:06 skington