With all due respect -- as I'm sure that Moose is techinically excellent -- I don't really understand how it is really any different from a practical perspective than most of the other full-featured class system generators for Perl.

You define a syntax for users to create constructors, accessors, etc. You've got some clean syntax and some stronger type-checking than some class builders, true, but the basic concept of providing an interface to generate a class hasn't changed a lot since, say, Class::MethodMaker (which goes back to 1996).

With almost any full system, you get the accessors and constructors 'for free' and don't need to know the details. For example:

package Stopwatch; use strict; use warnings; use DateTime; use Class::MethodMaker [ scalar => [ { -type => 'DateTime', -default_ctor => sub { DateTime-> +now }, 'timer' ], new => 'new', ]; sub diff { my $self = shift; $self->timer - DateTime->now; } # ... my $sw = Stopwatch->new; # ... wait a moment print $sw->diff;

Only when you move away from using accessors to get at encapsulated data does the underlying form really matter. For example, with inside-out objects:

package Stopwatch; use strict; use warnings; use DateTime; use Class::InsideOut qw( public register id ); public timer => my %timer => { set_hook => { $_->isa('DateTime') or die "must be a DateTime object" + } }; sub new { my $self = register( bless \(my $s) ); $timer{ id $self } = DateTime->now; return $self; } sub diff { my $self = shift; $time{ id $self } - DateTime->now; } # ... my $sw = Stopwatch->new; # ... wait a moment print $sw->diff;

Could you help me understand what's really different about Moose beyond syntax?

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.


In reply to Re^2: Your favorite objects NOT of the hashref phylum by xdg
in thread Your favorite objects NOT of the hashref phylum by blogical

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.