Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Class-Meta CPAN distribution.

Report information
The Basics
Id: 38277
Status: rejected
Priority: 0/
Queue: Class-Meta

People
Owner: Nobody in particular
Requestors: rcoops [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.62
Fixed in: (no value)



Subject: once and default attribute flags cause confusion
I build a small set of classes that happily worked together till I decided to upgrade to version 0.62 of Class::Meta (used to be on Class::Meta 0.53) The reason these clases all failed was because they where not set which is well strange but ok fair enough I added a default value to all attributes (not undef though that results in the same problem) and the classes where happy again. A second problem I had was with the once flag, in 0.53 I was able to define an attribute as being settable only once, then as soon as I set it I was unable to alter it's value which is what I expected to happen. Now in 0.62 I have to assign a value to the attribute when declaring it, any later and I get the told that the value must be defined. I am not sure if these things are bugs or desired behaviour from the authors point of view but at least to me both changes make very little sense.
You can work around both of these issues by passing a block to the constructor. The enforcement of `required` and `once` attributes is delayed until the constructor returns, and you can pass a block to the constructor to run code before it returns. It'd look something like this (where "name" might be a required or once attribute): my $thingy = MyApp::Thingy->new( age => 32, sub { my $thingy = shift; # age and attributes with default values are already set. my $name = calculate_name( $thingy ); $thingy->name($name); }, ); HTH, David