I've found a module called FEAR::API, which is a mix of LWP::UserAgent, WWW::Mechanize & friends, and realized that it heavily uses overload operators to do many things, such as:
fetch("google.com") > my $content; # also: fetch("google.com") | _print; # and even: url("google.com")->() >> _self | _save_as_tree("./root"); $_->() | _save_as_tree("./root") while $_;
For the sake of maintainability, ease of reading and best practices, do you think this kind of interface is a good design?

Isn't it misleading to use the ">" operator to write contents of something into a variable? Isn't it much cleaner to have something like this:

my $content = fetch("google.com");
And what about this:
url("google.com")->() >> _self | _save_as_tree("./root");
Aren't any of these options better:
# hmmm, looks confusing: save_as_tree("./root", fetch( url("google.com") ) ); # chained calls, but still confusing: url("google.com")->fetch()->save_as_tree("./root"); # full OO: my $url = Some::Module::Name->new( url => "google.com" ); $url->fetch; $url->save_as_tree("./root");
I've never written a Perl module that used overload and I believe I've used only a few modules that had it. So is it just me because I'm not used to it, or is this an example of overload abuse?

Shouldn't the ">" operator be used only to compare things, where that "thing" could be an object and its class could implement a specific comparision method?

For example, a class called Person could overload ">" when comparing two Person instances, and the comparision would be based on the age of each person.

Please let me know what your thoughts about this subject are.

PS: I have not read PBP completely yet, there must be something about this over there...


In reply to Overload abuse or is it just me? by salvix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.