Skip Menu |

This queue is for tickets about the MooseX-UndefTolerant CPAN distribution.

Report information
The Basics
Id: 53935
Status: stalled
Priority: 0/
Queue: MooseX-UndefTolerant

People
Owner: ether [...] cpan.org
Requestors: ether [...] cpan.org
pecho [...] belwue.de
cpan [...] punch.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: default value not set when passing undef in constructor
It would be nice if the default value was set when undef was passed into the constructor. (see attached test file)
Subject: default.t
#!/usr/bin/perl use Test::More; package Foo; use Moose; use MooseX::UndefTolerant::Attribute; has bar => ( is => 'rw', traits => ['MooseX::UndefTolerant::Attribute'], default => 'baz' ); 1; package main; my $foo = Foo->new( bar => undef ); is ( $foo->bar, 'baz', 'does the default value get set when passing undef in the constructor' ); done_testing();
From: cpan [...] punch.net
On Sat Jan 23 03:49:33 2010, cpan@punch.net wrote: Show quoted text
> It would be nice if the default value was set when undef was passed into > the constructor. (see attached test file)
The above test passes in 0.04. thanks. An additional test is attached. Apparently the "around('initialize_instance_slot', sub {" is not called when "__PACKAGE__->meta->make_immutable;" has been invoked. tOm on the #moose channel pointed me at MooseX::Emulate::Class::Accessor::Fast::Meta::Accessor, especially the "_generate_accessor_method_inline" sub. see: http://cpansearch.perl.org/src/FLORA/MooseX-Emulate-Class-Accessor-Fast-0.00903/lib/MooseX/Emulate/Class/Accessor/Fast/Meta/Accessor.pm irc log: (10:01:08 PM) th: the around('initialize_instance_slot' ... never gets called when __PACKAGE__->meta->make_immutable; is set. (10:01:41 PM) t0m: th: yes. (10:01:56 PM) t0m: that's as make_immutable inlines stuff for you :) (10:02:10 PM) t0m: your trait needs to override the generated accessors (10:02:23 PM) t0m: see MX::Emulate::Class::Accessor::Fast (10:02:28 PM) th: thanks (10:02:38 PM) t0m: for the trivial example of mangling that :) (10:03:02 PM) t0m: might not be quite what you need, but look at that, then read the code around where it's overriding things :) (10:05:39 PM) th: so I should be looking at the "around 'BUILD' => sub" part? (10:06:27 PM) th: it says (in mk_accessors): confess("You are trying to modify ${class}, which has been made immutable, this is ". "not supported. Try subclassing ${class}, rather than monkeypatching it") if $meta->is_immutable; (10:06:47 PM) t0m: http://cpansearch.perl.org/src/FLORA/MooseX-Emulate-Class-Accessor-Fast-0.00903/lib/MooseX/Emulate/Class/Accessor/Fast/Meta/Accessor.pm (10:07:20 PM) t0m: specifically, the code I wrote below the elucidating comment 'FIXME - this is shite, but it does work'
Subject: defaults_immutable.t
#!/usr/bin/perl use Test::More; package Foo; use Moose; use MooseX::UndefTolerant::Attribute; has bar => ( is => 'rw', traits => ['MooseX::UndefTolerant::Attribute'], default => 'baz' ); __PACKAGE__->meta->make_immutable; 1; package main; my $foo = Foo->new( bar => undef ); is ( $foo->bar, 'baz', 'does the default value get set when passing undef in the constructor and make_immutable is set' ); done_testing;
Subject: MooseX::UndefTolerant is not immutable-tolerant
the irc transcript should sum it up: 16:08 < shadowpaste> "Ether" at 217.168.150.38 pasted "MooseX::UndefTolerant::Attribute trait is not getting applied via sugar?" (58 lines) at http://paste.scsys.co.uk/53643 16:09 <@ether> I can't see what's going wrong here -- $attr->meta->does_role('MooseX::SetOnce::Attribute') is true, but the method modifier is not being applied properly 16:09 <@ether> I can see the original Moose::Meta::Attribute::initialize_instance_slot being called, but not the method mod 16:12 <@ether> I suspect this is another puzzle for doy :) 16:14 <@ether> (actually that paste example isn't quite right; the sugar class needs to be in a separate file for the exports to work, apparently) 16:14 <@autarch> ether: I think the MX::UndefTolerant docs are wrong 16:14 <@autarch> you can't apply it to a single attribute if you immutablize the class 16:14 <@autarch> this seems like it should be fixable 16:15 <@ether> interesting, supposedly the latest release was supposed to fix that 16:16 <@ether> but indeed the distro doesn't have tests for immutability, and they break when I add it 16:16 <@ether> so one would need to method-modify the inlined version of initialize_instance_slot, presumably 16:16 <@autarch> basically, making an attr tolerant needs to change the metaclass _or_ we need to push slot initialization inling from Constructor back to the attribute class somehow 16:16 <@autarch> the latter might actually be a better idea 16:17 <@autarch> the slot init code in MMM::Constructor is quite terrifying I'd be happy to help out -- please point me to your github repo (it's missing from META.yml) and hit me up on #moose.
For now, I would suggest: - TODO tests for the issue I describe (basically, t/attribute.t but with the classes made immutable) - documentation about this limitation.
On Tue Oct 19 16:27:26 2010, ETHER wrote: Show quoted text
> For now, I would suggest: > - TODO tests for the issue I describe (basically, t/attribute.t but with > the classes made immutable) > - documentation about this limitation.
Tests and documentation changes made on github and pull request sent; as soon as the inlined slot initialization code gets moved around (I think doy is working on it nowish) I'll add support for it.
Subject: MooseX::UndefTolerant::Attribute does not work if class is made immutable
Date: Tue, 27 Sep 2011 18:18:19 +0200
To: bug-MooseX-UndefTolerant [...] rt.cpan.org
From: Pecho <pecho [...] belwue.de>
Hi there, using perl 5.12.2 and MooseX::UndefTolerant version 0.12 I found MooseX::UndefTolerant::Attribute not working if the class was made immutable. Show quoted text
---- example code ---- package My::Class; use Moose; use MooseX::UndefTolerant::Attribute; has 'bar' => ( traits => [ qw(MooseX::UndefTolerant::Attribute)], is => 'ro', isa => 'Num', predicate => 'has_bar' ); # if made immutable MooseX::UndefTolerant::Attribute has no effect __PACKAGE__->meta->make_immutable; # Doesn't explode --> unfortunately it does if class is made immutable my $class = My::Class->new(bar => undef); print "Has it a bar ? ", $class->has_bar ? 'Yes': 'No'; ------------------------ This kind of error was reported earlier for MooseX::UndefTolerant and fixed in 0.06. May be it has survived for MooseX::UndefTolerant::Attribute ;-). Thanks for all your work Wolfgang
Subject: Re: [rt.cpan.org #71284] MooseX::UndefTolerant::Attribute does not work if class is made immutable
Date: Tue, 27 Sep 2011 13:42:32 -0700
To: Pecho via RT <bug-MooseX-UndefTolerant [...] rt.cpan.org>
From: Karen Etheridge <ether [...] cpan.org>
Show quoted text
> using perl 5.12.2 and MooseX::UndefTolerant version 0.12 > I found MooseX::UndefTolerant::Attribute not working if > the class was made immutable.
What version of Moose are you running?
Subject: Re: [rt.cpan.org #71284] MooseX::UndefTolerant::Attribute does not work if class is made immutable
Date: Wed, 28 Sep 2011 10:08:49 +0200
To: Karen Etheridge via RT <bug-MooseX-UndefTolerant [...] rt.cpan.org>
From: Pecho <pecho [...] belwue.de>
Hi Karen, I am running Moose version 2.0204. Perl version 5.12.2 is installed via perlbrew under Ubuntu 10.04. On Tue, Sep 27, 2011 at 04:42:45PM -0400, Karen Etheridge via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=71284 > >
> > using perl 5.12.2 and MooseX::UndefTolerant version 0.12 > > I found MooseX::UndefTolerant::Attribute not working if > > the class was made immutable.
> > What version of Moose are you running? >
This is a known limitation, documented in the CAVEATS section: Show quoted text
> This extension does not currently work in immutable classes when
applying the Show quoted text
> trait to some (but not all) attributes in the class. This is because the > inlined constructor initialization code currently lives in > L<Moose::Meta::Method::Constructor>, not L<Moose::Meta::Attribute>.
The good Show quoted text
> news is that this is expected to be changing shortly.
I should find my notes and figure out what the solution was that we had in mind for this -- if I recall, it depends on some changes to be made in Moose core first.
Subject: Re: [rt.cpan.org #71284] MooseX::UndefTolerant::Attribute does not work if class is made immutable
Date: Tue, 4 Oct 2011 13:08:03 +0200
To: Karen Etheridge via RT <bug-MooseX-UndefTolerant [...] rt.cpan.org>
From: Pecho <pecho [...] belwue.de>
Show quoted text
> This is a known limitation, documented in the CAVEATS section:
Ah, failed to notice that. I primarily looked at MooseX::UndefTolerant::Attribute docu. I found the error occurs only if you explicitly set the attribute to undef calling new. I hanle it in BUILDARGS. Thanks for your efforts.
Subject: Re: [rt.cpan.org #71284] MooseX::UndefTolerant::Attribute does not work if class is made immutable
Date: Tue, 4 Oct 2011 08:10:47 -0700
To: Pecho via RT <bug-MooseX-UndefTolerant [...] rt.cpan.org>
From: Karen Etheridge <ether [...] cpan.org>
On Tue, Oct 04, 2011 at 07:08:19AM -0400, Pecho via RT wrote: Show quoted text
> > This is a known limitation, documented in the CAVEATS section:
> Ah, failed to notice that. I primarily looked at MooseX::UndefTolerant::Attribute docu. > > I found the error occurs only if you explicitly set the attribute to undef calling new. > I hanle it in BUILDARGS.
Yes, if the role is only applied to the attribute but not the (meta)class itself, there is nothing to catch the undef argument in the inlined constructor. There was a plan to move some of the constructor logic in the guts of Moose into the attributes, so this interception is possible, but it hasn't happened yet; I will ping the Moose cabal again and see if we can get this done soon. I'll leave this issue open to track it.
Marking stalled, as I don't think there's anything we can do until changes are made to Moose core.