http://www.perlmonks.org?node_id=658664

EvanCarroll has asked for the wisdom of the Perl Monks concerning the following question:

OK, so in my quest to make Perl suck even less, I'm trying to hack in the ability to turn on v5.10 features with the usage of Moose, but only If perl is 5.10.

I'm not sure how to do this. Any ideas? The trick is you don't want Moose to be v5.10 only, but you want Moose to use feature ':5.10', if the version of the perl interpreter is v5.10+. This is tricky, because this information is known at compile-time, but I'm not sure how to do a compile time conditional that invokes the necessary 'use', to put the interpreter in 5.10 mode. When I was playing around with it a require wouldn't suffice.

The goal is simple to eliminate the need to use features ':5.10' all over the place. I realize the downside of this: upgrading interpreters has a higher probably of breaking v5.8 code (which is possible anyway).

Thanks in advance, one day Perl will suck even less.


Evan Carroll
www.EvanCarroll.com

Replies are listed 'Best First'.
Re: Trying to make perl suck less again
by ysth (Canon) on Dec 23, 2007 at 02:41 UTC
    feature is a lexically scoped pragma; there is no way (nor should there be) to turn it on everywhere.

    But to enable it in every module that uses Moose is easy: just add feature->import(":5.10") if $] >= 5.010; in Moose::import, the same as is done for the strict and warnings pragmas (sans conditional). And a use if $] >= 5.010, "feature", ":5.10"; at the top of Moose.pm.

    But this seems like a silly thing to do; I presume the real Moose distribution won't integrate a change like that, for the same reason that features aren't automatic in the first place: backwards compatibility.

    It would make more sense to have a module of your own used by everything you write that loads both Moose and 5.10 features (untested):

    package EvanPerl; use strict; use warnings; use Moose; use if $] >= 5.010, "feature", ":5.10"; sub import { feature->import(":5.10") if $] >= 5.010; goto &Moose::import; # can't just call Moose->import since it need +s to know the "correct" caller. } 1;
      Moose doesn't have to be backwards compatible, and quite frankly it is stupid perl is to such an ape shit insane extent - especially being Perl 6's state. If you use Moose, the package that includes Moose should use 5.10 features. It is the very job of Moose's to eliminate cruft, after all -- it's just regular perl code, that makes perl more bearable. Having to tell Perl your code isn't retardedly esoteric, and thus can use new features, is surely an easy target for Moose. And v5.10 broke stuff anyway right? Without going into the minor things I'm sure it broke, it removed the deprecated pseudohashes...

      IIRC the strongest reason to keep Moose out of the CORE amongst other stupid modules that compete to make perl-suck-less, was that Moose wanted to develop at a higher speed than that of CORE, and that people acknowledge it might break backwards compatibility.

      Every few major releases of Moose have broken something, somewhere for me. However, I waste substantially less time finding and fixing them than I did hitting my head over retarded design decisions that predate Moose. And more often than not, the new functionality Moose includes with every major release quickly laps the amount of time I waste when Moose is broken from upgrade.

      Ignore those that would stifle development because they refuse to risk breaking compatibility. programmer_conservatives--


      Evan Carroll
      www.EvanCarroll.com
        Thanks for explaining. I didn't know Moose regularly breaks compatibility. That's a little scary, if (as I believed to be the case) it is used by a number of CPAN authors, all of whom will be upgrading on their own schedules. Oh well.

        Update: the above was intended to be sarcastic. I assume that even if Evan's assertion that Moose has broken BC is true, it was accidental, not intentional.

          A reply falls below the community's threshold of quality. You may see it by logging in.
        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Trying to make perl suck less again
by perrin (Chancellor) on Dec 22, 2007 at 19:12 UTC
    It doesn't sound like a good idea to me, but I would try one of these:
    eval 'use feature q(5.10)'; # or require feature; feature->import('5.10');
      Uh, nice.

      PS -- I don't ever throw away bath water.


      Evan Carroll
      www.EvanCarroll.com
Re: Trying to make perl suck less again
by Burak (Chaplain) on Dec 22, 2007 at 20:33 UTC
    how about:
    BEGIN { if ( $] < 5.010000 ) { # also set some bool var like $NEW_PERL $INC{'feature.pm'} = 1; package feature; } } use feature ':5.10';

      Is there room for a backported feature.pm on the CPAN then?

      A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.