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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|