Skip Menu |

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

Report information
The Basics
Id: 68394
Status: resolved
Priority: 0/
Queue: MooseX-Role-ConstructorRoleApplication

People
Owner: Nobody in particular
Requestors: bobtfish [...] bobtfish.net
Cc:
AdminCc:

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



Subject: Please explain differences from MooseX::Traits in Pod
Date: Mon, 23 May 2011 13:16:23 +0100
To: bug-MooseX-Role-ConstructorRoleApplication [...] rt.cpan.org
From: Tomas Doran <bobtfish [...] bobtfish.net>
Hi. From an initial look, your module appears to be a re-implementation of MooseX::Traits. Can you explain in the Pod of your module why you should use your module instead of MooseX::Traits? Cheers t0m
On Mon May 23 08:14:49 2011, BOBTFISH wrote: Show quoted text
> Hi. > > From an initial look, your module appears to be a re-implementation > of MooseX::Traits. Can you explain in the Pod of your module why you > should use your module instead of MooseX::Traits? > > Cheers > t0m >
Sheesh... how the heck did I remain oblivious to MooseX::Traits all this time? In light of this, MooseX::Role::ConstructorRoleApplication is going to unceremoniously depart from this world. Thank you for enlightening me.
On Mon May 23 08:14:49 2011, BOBTFISH wrote: Show quoted text
> Hi. > > From an initial look, your module appears to be a re-implementation > of MooseX::Traits. Can you explain in the Pod of your module why you > should use your module instead of MooseX::Traits? > > Cheers > t0m >
After a closer look, it seems the existance of CRA is warranted. I have updated the Pod to explain differences and use cases in 0.03.
Thanks for the quick response! Show quoted text
> After a closer look, it seems the existance of CRA is warranted. I have > updated the Pod to explain differences and use cases in 0.03.
I'm sorry to be a pain in the ass, but this really doesn't explain it to me. You say: Use C<MooseX::Role::ConstructorRoleApplication> if you're a fan of L<Test::More>'s C<new_ok> or for other reasons require a single call to C<new> rather than a chain of calls (as would be necessary with C<MooseX::Traits>). Otherwise, use C<MooseX::Traits>. But MooseX::Traits provides a ->new_with_traits method which internally calls ->with, then ->new on the result.. Isn't that the functionality you are noting as different?
On Tue May 24 03:27:16 2011, BOBTFISH wrote: Show quoted text
> Thanks for the quick response! >
> > After a closer look, it seems the existance of CRA is warranted. I have > > updated the Pod to explain differences and use cases in 0.03.
> > I'm sorry to be a pain in the ass, but this really doesn't explain it
to me. Show quoted text
>
No pain at all. Show quoted text
> You say: > > Use C<MooseX::Role::ConstructorRoleApplication> if > you're a fan of L<Test::More>'s C<new_ok> or for other reasons require a > single call to C<new> rather than a chain of calls (as would be necessary > with C<MooseX::Traits>). Otherwise, use C<MooseX::Traits>. > > But MooseX::Traits provides a ->new_with_traits method which internally > calls ->with, then ->new on the result.. Isn't that the functionality > you are noting as different?
Good point. Further clarification is needed. The (sole) advantage, then, is that you can use it with code (other modules, e.g. Test::More) that calls ->new on a given package. I can not see any way that you could use new_ok (as an example I am familiar with; there may be others) with MooseX::Traits. Then again, I could be completely blind to an obvious solution, in which case I welcome further enlightenment.
On Tue May 24 07:42:16 2011, FRASE wrote: Show quoted text
> Good point. Further clarification is needed. The (sole) advantage, > then, is that you can use it with code (other modules, e.g. Test::More) > that calls ->new on a given package. I can not see any way that you > could use new_ok (as an example I am familiar with; there may be > others) with MooseX::Traits.
Here you're correct. This is entirely a design decision from MooseX::Traits, as overloading new to do something other than pure construction was/is considered bad practice, and most of the time whatever you're doing can easily be done a different way (e.g. writing your own new_ok function that called ->new_with_traits if present) is trivial.
On Tue May 24 08:35:27 2011, BOBTFISH wrote: Show quoted text
> On Tue May 24 07:42:16 2011, FRASE wrote:
> > Good point. Further clarification is needed. The (sole) advantage, > > then, is that you can use it with code (other modules, e.g. Test::More) > > that calls ->new on a given package. I can not see any way that you > > could use new_ok (as an example I am familiar with; there may be > > others) with MooseX::Traits.
> > Here you're correct. > > This is entirely a design decision from MooseX::Traits, as overloading > new to do something other than pure construction was/is considered bad > practice, and most of the time whatever you're doing can easily be done > a different way (e.g. writing your own new_ok function that called > ->new_with_traits if present) is trivial.
Well, one ends up writing either a replacement for new_ok (or some other affected function) or a MooseX::Traits-ish role. I have updated the POD once more; if you feel further discussion or clarification is needed, let me know your suggestions.
On Tue May 24 08:35:27 2011, BOBTFISH wrote: Show quoted text
> On Tue May 24 07:42:16 2011, FRASE wrote:
> > Good point. Further clarification is needed. The (sole) advantage, > > then, is that you can use it with code (other modules, e.g. Test::More) > > that calls ->new on a given package. I can not see any way that you > > could use new_ok (as an example I am familiar with; there may be > > others) with MooseX::Traits.
> > Here you're correct.
Not for that particular example, anyway. my $obj = new_ok($class->with_traits(...), \@args, $test_name); with_traits just returns a new class, so there's no reason you can't call new_ok on it.
On Wed May 25 07:32:52 2011, HDP wrote: Show quoted text
> On Tue May 24 08:35:27 2011, BOBTFISH wrote:
> > On Tue May 24 07:42:16 2011, FRASE wrote:
> > > Good point. Further clarification is needed. The (sole) advantage, > > > then, is that you can use it with code (other modules, e.g.
Test::More) Show quoted text
> > > that calls ->new on a given package. I can not see any way that you > > > could use new_ok (as an example I am familiar with; there may be > > > others) with MooseX::Traits.
> > > > Here you're correct.
> > Not for that particular example, anyway. > > my $obj = new_ok($class->with_traits(...), \@args, $test_name); > > with_traits just returns a new class, so there's no reason you can't > call new_ok on it.
The anonymous class returned by with_traits() does not appear in the class' @ISA, so new_ok fails (as would any other operation calling $obj->isa($result_of_with_traits).
On Wed May 25 09:02:41 2011, FRASE wrote: Show quoted text
> > my $obj = new_ok($class->with_traits(...), \@args, $test_name); > > > > with_traits just returns a new class, so there's no reason you can't > > call new_ok on it.
> > The anonymous class returned by with_traits() does not appear in the > class' @ISA, so new_ok fails (as would any other operation calling > $obj->isa($result_of_with_traits).
Either we've miscommunicated or you didn't try it: { package Stuffy; use Moose::Role; } { package Stuff; use Moose; with 'MooseX::Traits'; } use Test::More; my $obj = new_ok(Stuff->with_traits('Stuffy')); done_testing; # output: ok 1 - The object isa MooseX::Traits::__ANON__::SERIAL::1 new_ok doesn't care that the anonymous class isn't in Stuff's @ISA, because new_ok doesn't know anything about Stuff, because you didn't pass it Stuff as an argument; you passed in the automatically generated class name from with_traits. with_traits does return a new anonymous class each time you call it, which may be contributing to your confusion -- that is, this second test would fail: isa_ok($obj, Stuff->with_traits('Stuffy')) I think that's arguably a bug (and there is an RT ticket for it), but it's unlikely to be a real limitation in any case. Checking isa('Stuff') and/or does('Stuffy') is the right thing to do, not checking isa($autogenerated_class). If you still have a case in mind where with_traits is insufficient, can you please show code?
On Wed May 25 13:57:20 2011, HDP wrote: Show quoted text
> On Wed May 25 09:02:41 2011, FRASE wrote:
> > > my $obj = new_ok($class->with_traits(...), \@args, $test_name); > > > > > > with_traits just returns a new class, so there's no reason you can't > > > call new_ok on it.
> > > > The anonymous class returned by with_traits() does not appear in the > > class' @ISA, so new_ok fails (as would any other operation calling > > $obj->isa($result_of_with_traits).
> > Either we've miscommunicated or you didn't try it: > > { > package Stuffy; > use Moose::Role; > } > { > package Stuff; > > use Moose; > with 'MooseX::Traits'; > } > > use Test::More; > > my $obj = new_ok(Stuff->with_traits('Stuffy')); > done_testing; > > # output: > ok 1 - The object isa MooseX::Traits::__ANON__::SERIAL::1 > > new_ok doesn't care that the anonymous class isn't in Stuff's @ISA, > because new_ok doesn't know anything about Stuff, because you didn't > pass it Stuff as an argument; you passed in the automatically generated > class name from with_traits. > > with_traits does return a new anonymous class each time you call it, > which may be contributing to your confusion -- that is, this second test > would fail: > > isa_ok($obj, Stuff->with_traits('Stuffy')) > > I think that's arguably a bug (and there is an RT ticket for it), but > it's unlikely to be a real limitation in any case. Checking > isa('Stuff') and/or does('Stuffy') is the right thing to do, not > checking isa($autogenerated_class). > > If you still have a case in mind where with_traits is insufficient, can > you please show code?
You're right; it turned out to be a design decision in our code that caused new_ok to fail. After much to-ing and fro-ing, it's back to the original conclusion: MooseX::Role::ConstructorRoleApplication is headed for the bit bucket. Thanks all for your advice.