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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |