http://qs321.pair.com?node_id=11146321


in reply to What if Perl had an OO standard library?

Venus is a rich demonstration that it is possible to implement "Everything is an object" in Perl. But honestly, I doubt that it is much more than that.

Objectification of arrays and hashes makes it look like Java, which isn't bad, but no particular benefit either. It gets weird when primitives like numbers and strings are objectified. Venus::Number objects can, thanks to overload, be manipulated with the usual arithmetic operators. However, as soon as I apply an arithmetic operator on a Venus number, the result loses its object properties and is just a plain number. There are no methods like $one->add($two) which would allow to return new Venus::Number objects.

Here's some experiments I ran. Some results weren't as I expected.

use 5.028; use Venus qw(catch); use Venus::Number; my $one = Venus::Number->new(1); my $two = Venus::Number->new(2); say "one = ", $one; # one = 1 say "one = $one"; # Argument "one = " isn't numeric in addition (+) .... # 10 <---- Venus::Number objects don't interpolate print "two = "; $two->print_string; print "\n"; # two = 2 <--- Methods don't interpolate either # Arithmetics my $three = $one + $two; say "three = ", $three; # three = 3 <---- Now it does interpolate print "three = "; $three->print_string; print "\n"; # Can't locate object method "print" via package "3" # <---- but has lost its blessing # Strings use Venus::String; my $just = Venus::String->new('Just'); my $another = Venus::String->new('another'); my $perl = Venus::String->new('Perl'); my $hacker = Venus::String->new('hacker'); say "$just $another $perl $hacker"; # ----> hackerPerlanotherJust