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


in reply to Recap: The Future of Perl 5

Note that Perl does ship with a (still) core module called Class::Struct, which offers a simple syntax for OO programming.

An example I wrote 2 years ago is somewhat similar to the Point class example you provided. I only wrote it as a rebuttal to a claim that Perl OO programming is very hard without installing something from CPAN

package Planet; use Class::Struct mass => '$', radius => '$'; use Math::Trig; sub density { my $self = shift; my $vol = 4/3*pi*($self->radius)**3); return $vol/($self->mass); } package main; use Planet; my $Jupiter = Planet->new(mass => 1.8E27, radius => 6.9E7); print "Jupiter has mass of " . $Jupiter->mass . " and "; print "radius of " . $Jupiter->radius . "\n"; print "It's density is " . $Jupiter->density . "\n";

Not as clean as your proposed syntax, but is something that can be used without needing anything from CPAN. And there are limitations, such as Class::Struct classes can only inherit from UNIVERSAL.


Edit: corrected syntax as pointed out by LanX. Also, changed mod:// links to doc://