in reply to Re: Types::DateTime, DateTimeUTC->plus_coercions( Format['ISO8601'] ), output format override question
in thread Types::DateTime, DateTimeUTC->plus_coercions( Format['ISO8601'] ), output format override question

Though it's not set if the attribute is set by a default/builder.

That makes this a particularly bad solution, then.

  • Comment on Re^2: Types::DateTime, DateTimeUTC->plus_coercions( Format['ISO8601'] ), output format override question

Replies are listed 'Best First'.
Re^3: Types::DateTime, DateTimeUTC->plus_coercions( Format['ISO8601'] ), output format override question
by tobyink (Canon) on Dec 26, 2019 at 09:26 UTC

    Why? OP isn't using a default or builder. (Not in the example anyway.)

      It violates the fundamental principle of least surprise. The code fails in subtle fashion.

        The trigger gets fired whenever a value is explicitly set for an attribute, but not when it's implicitly set by a default/builder. Basically, it's triggered by the outside world setting a value, but not triggered by the internal workings of the attribute. The default/builder is itself a coderef though, so can execute arbitrary code, including doing whatever the trigger would do.

        I don't think this violates the principle of least surprise if you consider the usual definition of "trigger". A trigger is a device that responds when it is pressed. You press the trigger on an attribute by supplying a value for it. If you don't supply a value for it, then the trigger doesn't get pressed.

        In any case, Moose has had this behaviour for triggers since they were introduced in 2006, and changing it would break a lot of stuff.