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 separate

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

  • I wonder if the newly released Devel::BeginLift is a way to solve the problem.

    I like your MooseX::Atom, but I rather see the problems you mentioned solved without having to rewrite all of my Moose code.

    --
    life is short
  • MooseX::Declare [p3rl.org] doesn't do what you want?
    • That would fall into the category of

      "b) Use this SECOND heavy sugar layer on top of the FIRST sugar layer, on top of Class::MOP."

    • To further clarify based entirely on memory load overhead (using only require, so without any work done in import methods).

      Perl                       3.1 meg
      Perl + Moose              11.8 meg
      Perl + MooseX::Declare    21.6 meg

  • First, as a minor nit, you can declare multiple attributes at once, which is a little less repetitive.

    has [qw( this that )] => ( is  => 'ro', isa =>'Str' );

    As for "with", do you understand in what cases you need to put "with" after you declare your attributes? Even if you do, does everyone on your team (now and in the future)?

    The thing I've come to appreciate about Moose is that it expects you to know what you're doing. E.g. you compose roles after attributes when roles require those attri

    • The idea of encapsulation is the very reason that we have most APIs.

      The idea that you don't NEED to know how something is implemented is always going to be better, as long as that lack of knowledge does not compromise the integrity of the systems or lead to perverted incentives.

      What good is a car that requires an intimate understanding of the underlying engine and brakes and gearbox. It might be handy if you are an enthusiast of a racing car driver or pushing the limits in some other dimension.

      What good is

      • It sounds like you're talking about encapsulation from the standpoint of users and APIs, which is different. Or, rather, it's the same but applied to Moose itself rather than what someone is designing using Moose.

        Unlike users, the designers of a system must understand the dynamics of the design. That can't be safely abstracted away. Role composition is a design activity that involves satisfying certain constraints and avoiding certain conflicts in order to get the desired behaviors.

        My point was that the

      • The composition order of roles is not an implementation detail of Moose; it’s a design concern of the creator of the class into which the roles get composed. To ask for it to be abstracted away is like calling maths is badly designed because 3 + 5 * 2 yields different results based on the order in which you evaluate the terms.

  • I've got a bunch of places where I generate attributes at module run time. This is useful when attributes have things in common.

    Theoretically, Moose could use Hooks::EndOfScope like namespace::clean, but having a dividing line in the middle of a module can be useful.

    If someone would get his act together, we'd have a non-dev release of Perl::Critic::Moose out that can check a lot of this stuff for you, e.g. that you don't use with() multiple times.