mop problem 6 - need improvement of current perl object system

I don't like that mop user tend to look down the user of current perl Object system.

Moose is great! Current Perl object system is not good!

No, No, No.

Current Perl object system is good. There are no lack to do Object Oriented program. Any program can be created by single inheritance and delegation.

At first, I hope improvement of current Perl OO system. Why from now we should write the following code? At first, I hope simple syntax of the following code before mop release.

package Foo;
use Base 'BaseObject';

sub new {
my $class = shift;
my $self = ref $_[0] eq 'HASH' ? $_[0] : {@_};
return bless $self, $class;
}

sub x {
my $self = shift;

if (@_) {
$self->{x} = $_[0];
}
else {
return $self->{x}
}
}

package main;
my $foo = Foo->new;
$foo->x(1);
print $foo->x;

For example.

class Foo {
  has x;
}

package main;
my $foo = Foo->new;
$foo->x(1);
print $foo->x;

And current object system can have array reference or scalar reference, etc. I hope simple syntax of these.

# Data is array reference
package Foo;
sub new {
  my $class = shift;
  my $self = [];
  return bless $self, $class;
}
package main;
my $foo = Foo->new;
print $foo->[0];

# Data is scalar reference
package Bar;
sub new {
my $class = shift;
my $self = '';
return bless \$self, $class;
}
package main;
my $foo = Foo->new;
print $$foo;

For example.

class Foo is ArrayStrage([]) {

}
package main;
my $foo = Foo->new;
print $foo->[0];

# Data is scalar reference
class Bar is ScalarStrage('') {

}
package main;
my $foo = Foo->new;
print $$foo;


1 Comment

Introducing a mop into core will not keep you from writing your constructors however you want them.

Leave a comment

About Yuki Kimoto

user-pic I'm Perl Programmer. I LOVE Perl. I want to contribute Perl community and Perl users.