Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Is there any way I can use object.method() instead of object->method()?

( #189327=categorized question: print w/ replies, xml ) Need Help??
Contributed by QwertyD on Aug 11, 2002 at 20:02 UTC
Q&A  > object-oriented programming


Description:

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?

Answer: Is there any way I can use object.method() instead of object->method()?
contributed by belg4mit

Filter::Simple comes with a sample filter for this named DotsForArrows.

Answer: Is there any way I can use object.method() instead of object->method()?
contributed by Anonymous Monk

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.

Answer: Is there any way I can use object.method() instead of object->method()?
contributed by jeffa

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 ...

Answer: Is there any way I can use object.method() instead of object->method()?
contributed by dada

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.

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (5)
    As of 2014-07-24 03:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (156 votes), past polls