$cat test_moose.pl
package NumberHolder;
use Moose;
has 'x' => (is => 'rw', isa => 'Int');
has 'y' => (is => 'rw', isa => 'Int');
__PACKAGE__->meta->make_immutable;
package Main;
my $z = NumberHolder->new(x => 1, y => 2);
print "z's x and y = ", $z->x()," ", $z->y(), "\n";
$time perl test_moose.pl
z's x and y = 1 2
real 0m1.48s
user 0m1.06s
sys 0m0.11s
No Moose
$cat test_nomoose.pl
package NumberRun;
sub new {
my $class = shift;
my %args = @_;
my %h = ( x => 0, y => 0);
@h{ keys %args} = values %args;
return bless \%h;
}
sub x {
my $self = shift;
$self->{x} = shift if @_;
$self->{x};
}
sub y {
my $self = shift;
$self->{y} = shift if @_;
$self->{y};
}
1;
package Main;
use strict;
use warnings;
my $z = NumberRun->new(x => 1, y => 2);
print "z's x and y = ", $z->x()," ", $z->y(), "\n";
$time perl test_nomoose.pl
z's x and y = 1 2
real 0m0.07s
user 0m0.01s
sys 0m0.01s
|