I think it's easy to see that the latter syntax scales much better.
I don't see that. Even with your short example and, I think, a good understanding of your module, I find the "before" much easier to read than the "after." I'm having a hard time even determining whether the "after" version is correct or not. For instance, you are creating a closure within a method call within an assignment to the very variable your closure uses... does that work? What is the value of $file_dialog there?
The fact that you can't prevent collisions between your methods and those of the class you are proxying is a real problem. The best you can do is make the collisions less likely by requiring the user to deal with uglier method names. Breaking tradition and using underscores for public methods doesn't seem satisfactory. (Wouldn't you rather reinforce a tradition which makes good sense?)
It seems that all your module is really doing is providing some syntactic sugar to avoid some typing. You can make the "before" code cleaner without resorting to OO contortions. One way to clean it up a bit:
And you could do quite a bit better if you wrote a little utility function to handle the common button initialization.my $file_dialog = Gtk::FileSelection->new("File Selection Demo"); { my $b = $file_dialog->ok_button; $b->label("Load"); $b->relief("half"); $b->width(80); $b->height(50); $b->signal_connect(clicked => sub { print $file_dialog->get_filename(), "\n"; }); } { my $b = $file_dialog->cancel_button; $b->label("Exit"); $b->relief("half"); $b->width(80); $b->height(50); $b->signal_connect(clicked => sub { Gtk->main_quit }); } $file_dialog->set_filename("penguin.png"); $file_dialog->signal_connect(destroy => sub { Gtk->main_quit }); $file_dialog->show();
In summary, I don't see a real benefit to using this module. I would avoid it as it doesn't seem to do much but provide a small syntactical shortcut, and that, IHMO, at the cost of clarity. For what it's worth, I can't think of a better way to do what you are attempting to do. (I just wouldn't attempt it at all.)
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Re: RFC: Class::Proxy::MethodChain
by sauoq
in thread RFC: Class::Proxy::MethodChain
by Aristotle
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |