Hello fello monks,

I'm writing Perl bindings for Etk, a toolkit for the new Enlightenment Foundation Libraries (link).

The bindings are now almost completed, and I'm now trying to work on an easy to use API for perl.

As an example, in Etk there are different functions to create a button widget:

Etk_Widget *etk_button_new(); Etk_Widget *etk_button_new_with_label(const char *label); Etk_Widget *etk_button_new_from_stock(Etk_Stock_Id stock_id); // Etk_S +tock_Id is an enum

Here is my translation of this into the perl module:

sub new { my $class = shift; my $self = $class->SUPER::new(); if(@_ == 1) { my $thing = shift; $self->{WIDGET} = $thing =~ /\D/ ? Etk::etk_button_new_with_label($thing) : Etk::etk_button_new_from_stock($thing); } else { $self->{WIDGET} = Etk::etk_button_new(); } bless($self, $class); return $self; }

As you can see, I'm trying to stuff different calls inside the same perl method in the spirit of DWIMmery.

Similarly, for example, there's the tree sorting callbacks, it acts differently based on what is passed ar ound. Example:

$tree->Sort( \&sort_func, $asc, $column); # the same routine but without a coderef works differently $tree->Sort(NUMERIC, $asc, $column); # where NUMERIC is a constant, and thus the sorting is done in C to ma +ke it faster and avoid the roundtrip to perl.

Now, problem is that one of the developers of the Etk library is saying that this is a bit confusing for t he user, so I'm asking you fellow monks:

P.S: Anyone interested in checking the code out, it's in CVS in the enlightenment reposit ory accessible from the enlightenment website. It's in the proto/etk-perl module (Note that you need to compi le proto/etk for this to work)

Thanx for your comments and replies.

--
Leviathan.

In reply to Question about module interface style by Leviathan

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.