http://www.perlmonks.org?node_id=189327

QwertyD has asked for the wisdom of the Perl Monks concerning the following question: (object-oriented programming)

I really like that in Perl 6, binary "." will be used to denote object hierarchy instead of binary "->". Is there some way I can start using "." for objects and " _ " for concatenation now?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: Is there any way I can use object.method() instead of object->method()?
by belg4mit (Prior) on Aug 11, 2002 at 22:33 UTC
    Filter::Simple comes with a sample filter for this named DotsForArrows.
Re: Is there any way I can use object.method() instead of object->method()?
by Anonymous Monk on Aug 12, 2002 at 01:44 UTC
    No, not really. Filter::Simple has been mentioned as a possibility (and its DotsForArrows demo), but this is very, very far from being robust (and only attempts the . to -> filtering, not the _ to . filtering). It can not be used as anything more than a (broken) toy filter.
Re: Is there any way I can use object.method() instead of object->method()?
by jeffa (Bishop) on Aug 11, 2002 at 22:26 UTC
    I searched CPAN for Perl6 and did not find any modules that offer that ability yet. You could do something like:
    use strict; my $code = do {local $/;<DATA>}; $code =~ s/(\w)\.(\w)/$1->$2/g; $code =~ s/(?<!\w)_(?!\w)/./g; eval $code; die $@ if $@; __DATA__ my $foo = Foo.new(); $foo.foo('foo'); $foo.bar('bar'); $foo.baz('baz'); print $foo.foo _ "\n" _ $foo.bar _ "\n" _ $foo.baz _ "\n"; package Foo; use Class::MethodMaker new => 'new', get_set => [ qw /foo bar baz / ];
    but not only is that twisted (and silly), there is more than likely some usage of . and _ that i missed with the regexes. Best to just stick with the arrow notation - it is only one more character to type, after all ... that or start using Python ... /duck

    UPDATE: belg4mit++ for suggesting Filter::Simple - i missed that one ...

Re: Is there any way I can use object.method() instead of object->method()?
by dada (Chaplain) on Aug 22, 2002 at 10:12 UTC
    there's also the PlusPlus module on CPAN which does this (and a couple more, equally evil things :-).

    As for the mentioned DotsForArrow, this one is also based on Filter trickeries.

Re: Is there any way I can use object.method() instead of object->method()?
by dada (Chaplain) on Aug 22, 2002 at 10:13 UTC
    there's also the PlusPlus on CPAN which does this (and a couple more, equally evil things :-).

    As for the mentioned DotsForArrow, this one is also based on Filter trickeries. -- to be deleted

    Originally posted as a Categorized Answer.