NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Moose Notes (Score:2)
I wasn't aware that the extends needs to be in a BEGIN block unless you really do have code which needs to happen at BEGIN time. Am I wrong? (Could be).
Also, with accepts a list and using multiple with statements should be avoided unless you have a very, very good reason to do so. A single with statement is like this:
Using it like that gets you the method conflict resolution. Using separate with statements is not only overly verbose, but it composes each role in separately. Since a role method is silently discarded if the class provides a method of the same name, if Does::Role1 provides a munge method and Does::Role2 also tries to provide it, you will never get Does::Role2's method composed in if you use with separately, but you will get a proper conflict when you use them at the same time.
Also, if you want to provide a default is for the has, make it 'ro' instead of 'rw'. It tends to be far more correct and makes it harder for people to accidentally alter the object's state in incompatible ways.
Reply to This
Re: (Score:2)
Eek, roles behaviour differently depending on whether you do them separately or together?
Yet another reason to be annoyed :(
Re: (Score:2)
Eek, Perl's built-ins behave differently depending on whether or not you call them in scalar context? Yet another reason to be annoyed! ;)
Seriously, it will take you about 3 seconds to get used to this behaviour of the with function and it's behaviour you want.
If you must write an alternative to the Moose API, I strongly recommend that you use Moose for a few months to get really comfortable with it and make sure you understand the design implications. Moose is great and well worth the learning curve.
Re: (Score:2)
It's not a case of getting used to it.
It's that it's a gotcha that the API should never have allowed.
And our team HAS been using Moose for several months. MooseX::Atom is the summary of all the bits of it we don't like.
Re: (Score:1)
Actually there are very good reasons why there are two ways to compose roles.
The ideal way to compose roles is to do it all at once like Ovid showed. This takes better advantage of conflict checking because it first creates a composite role of all the roles passed to
withand then applies that role to the class.The second way is to have multiple
wRe: (Score:2)
No, this does NOT count as "heavy".
Re: (Score:1)
You're not wrong. Extending the parent class needs to happen at compile time in Catalyst because as dagolden mentions elsewhere Catalyst choose once upon a time to support ... hence the BEGIN.
sub foo : Path(/) { }syntax. The nature of that syntax and how Perl goes about making it "work" requires your class hierarchy to be resolved at compile time