Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Mouse as prelude to Moose?

by metaperl (Curate)
on Feb 05, 2009 at 16:37 UTC ( [id://741597]=perlquestion: print w/replies, xml ) Need Help??

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

I needed something to save me from writing my own constructors. I love Moose but it scares me because it is heavyweight and has lots of dependencies. However, it is actively developed and there probably would be no problems.

That being said, I recently reached for Class::Base and started my work. But I find the accessor specs for Class::Base to be a bit more involved than I like... in a way they are nice because you can do anything you want in the init() method to verify anyway you want.

But I think using Mouse as a prelude to Moose is a good thing. Do we have any recent feedback on whether Moose will become a part of Perl core in a upcoming Perl release?

Any +/- feedback on Mouse?

Replies are listed 'Best First'.
Re: Mouse as prelude to Moose?
by stvn (Monsignor) on Feb 05, 2009 at 22:08 UTC
    Any +/- feedback on Mouse?

    Let me first say that Mouse is a stop-gap measure for people and situations where Moose is just not appropriate, such as:

    • Vanilla CGI scripts
    • Command Line apps that need fast startup
    • Low resource environments (minimal memory and/or minimal CPU)
    • Restricted deployment environments (hard to get modules installed, etc)
    It will be actively maintained until we can fix Moose to perform in those situations listed above.

    It should be noted that Mouse and Moose are about tied for runtime performance (if all the proper optimizations are applied) so unless your requirements match those listed above there is no sizable runtime performance boost you get from Mouse over Moose.

    I will agree with your point that Moose is heavyweight, but the many dependencies is a typically overstated issue. If you have an environment where you can install modules, then what is the difference between typing install Moose vs. install Mouse?

    Do we have any recent feedback on whether Moose will become a part of Perl core in a upcoming Perl release?

    The problem with becoming "core" is that it freezes your module in time; bugs, issues and all. Moose is still being actively developed and improved upon and so needs a much more frequent releases then "core" could provide. If we were to put it into "core" the result would not really have much benefit if a user still needed to upgrade Moose from CPAN. Additionally, if you "core" Moose, then you would also need to core all it's dependencies as well, which means the same problems I described for Moose would then be taken on by these other modules.

    In short, making a module "core" is not really a good thing so one that I would be resistant to (unless, as chromatic has suggested, the core Perl release schedule is radically changed and becomes much more frequent).

    -stvn
Re: Mouse as prelude to Moose?
by metaperl (Curate) on Feb 05, 2009 at 16:41 UTC
    hmm that's cute, you can mis-spell 'is' and the code still works:
    package M1; use Mouse; has 'x' => (is => 'rw'); has 'y' => (ks => 'rw'); 1; use M1; my $m = M1->new(x => 55); warn $m->x; $m->x(888); warn $m->x;
    UPDATE it's not that it works because the accessor is not actually formed. It's just no error is thrown. Just put a call to $m->y and you will see Can't locate object method "y" via package...

      By default Moose (and I'd assume also Mouse) will allow you to pass any keys you want to an object constructor. So what happens is just that the ks is being ignored. The reason it doesn't throw an error for an unknown key is so you can do something like this:

      package Foo; use Moose; has 'number' => ( is => 'rw', isa => 'Num', ); sub BUILD { my ( $self, $args ) = @_; $self->number( $args->{ 'foo' } * 42 ); }

      You can turn this behavior off for your own modules with MooseX::StrictConstructor.


      www.jasonkohles.com
      We're not surrounded, we're in a target-rich environment!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://741597]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found