Stories
Slash Boxes
Comments
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 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:

    with qw(Does::Role1 DoesRole2);

    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.

    • Eek, roles behaviour differently depending on whether you do them separately or together?

      Yet another reason to be annoyed :(

      • 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.

        • 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.

          • Eek, roles behaviour differently depending on whether you do them separately or together?
            It's that it's a gotcha that the API should never have allowed.

            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 with and then applies that role to the class.

            The second way is to have multiple w

            • No, this does NOT count as "heavy".

              Perl                     3,120 K
              Perl + Moose            11,840 K
              Perl + MooseX::Atom     11,852 K

    • 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).

      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 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 ... hence the BEGIN.