In continuation to
I tried to hack a proof of concept for a concise OO syntaxThe basic ideas are that:
Declaration of instance variable
- my on the class level with :attributes
- the TYPE is given right after the my
- attributes reflect the Moo(se-)model of has keys where possible
- the assigned values are defaults for the new-constructor
Access of instance variables inside methods
- an instance variable x is readable and writable via $$x
- this is automatically mirrored in $self->{x}
- $self->{x} is an alternative syntax for the same access
$self
- $self is already shifted from @_ and directly available
Methods
- all subs declared inside the scope of a class are methods
- imported subs (like pp) are ignored
{ use Class BLA => ISA-LIST; use Data::Dump qw/pp/; my Int ($x,$y) :has :rw = (10,11); sub set_x { my ($var) = @_; #warn "set_x $$x -> $var \n"; $$x = $var; } sub print_x { print "x = $$x \n"; } sub print_self_x { print "x = $self->{x} (via \$self)\n"; } sub dump { warn '$self:',\$self; warn pp '$self: ', $self; warn pp '$$x: ', $$x; warn pp '$$y: ', $$y; } }
The implementation is done via a macro expansion from use Class which injects some boilerplate into the head of the class, which handles the creation.
Injecting is basically done via a source filter or alternatively via Keyword::Simple. NB: just injecting some code doing introspection. No parsing, regexing or modification of the code you see.
I'm supposing this concise syntax could be used as a front end for all current OO models in Perl and might help offering a stable backwards compatible syntax if it's hardcoded into the engine.
A rough proof of concept follows here:
NB: This example is pretty barebone, and not meant to be an alternative to other OO Frameworks, but rather a frontend. It doesn't create accessors and the constructor is only simplistic.
Comments?
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice