Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I've thought about this some more, and written a few more examples.

This example shows the translation of using aggregate object accessors to the appropriate C:P:MC syntax:


my $file_dialog = Gtk::FileSelection->new("File Selection Demo"); $file_dialog->ok_button->label("Load"); $file_dialog->ok_button->relief("half"); $file_dialog->ok_button->width(80); $file_dialog->ok_button->height(50); $file_dialog->ok_button->signal_connect(clicked => sub { print $file_dialog->get_filename(), "\n"; }); $file_dialog->cancel_button->label("Exit"); $file_dialog->cancel_button->relief("half"); $file_dialog->cancel_button->width(80); $file_dialog->cancel_button->height(50); $file_dialog->cancel_button->signal_connect(clicked => sub{Gtk->main_q +uit}); $file_dialog->set_filename("penguin.png"); $file_dialog->signal_connect(destroy => sub{Gtk->main_quit}); $file_dialog->show();
my $file_dialog; $file_dialog = Gtk::FileSelection ->Class::Proxy::MethodChain::new("File Selection Demo") ->ok_button->ret_wrap(sub {shift ->label("Load") ->relief("half") ->width(80) ->height(50) ->signal_connect(clicked => sub { print $file_dialog->get_filename()->ret_val, "\n"; }); }) ->cancel_button->ret_wrap(sub {shift ->label("Exit") ->relief("half") ->width(80) ->height(50) ->signal_connect(clicked => sub{Gtk->main_quit}); }) ->set_filename("penguin.png") ->signal_connect(destroy => sub{Gtk->main_quit}) ->show();

I think it's easy to see that the latter syntax scales much better.

I had been thinking that the ->ret_val() syntax is just too bulky and was toying with the idea of having AUTOLOAD() extract pre(or suf)fixes from the called method's name. Eventually I decided against it - I don't think it's better as it'll only cover one case (albeit probably the most or second most common one - getting the return value of the last method call) and complicate AUTOLOAD() needlessly. A name change on C:P:MC's methods would do just as good a job without the added hassle.

I'm thinking of ->_ret() instead of ->ret_val() and ->_proxy() instead of ->ret_wrap(). ->ret_val() is horribly named to begin with, in retrospect - a function can return more than a single value, after all. I am leaning on ->_proxy() because ->_wrap() strikes me as indescriptive.

Now I know underscores are usually used for private methods and that's actually exactly the reason I'd like to use them here. It's unlikely that another module will expose public methods with such names, which minimizes the potential need to reach for the ->call() escape. For the same reasons I'm pondering renaming it to ->_call().

Of course all that means the ->wrap() constructor becomes ->proxy() as well for consistency and leads me to wondering if it's not maybe a good idea to make that one an exported function instead of a constructor. That way no C:P:MC method would start without an underscore, so collisions with wrapped object's public methods' names are far less likely.

Makeshifts last the longest.

In reply to Re: RFC: Class::Proxy::MethodChain by Aristotle
in thread RFC: Class::Proxy::MethodChain by Aristotle

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (4)
    As of 2018-05-25 13:25 GMT
    Find Nodes?
      Voting Booth?