in reply to Re: converting libraries into modules
in thread converting libraries into modules

Ugh, please don't do that. It's brittle to maintain, hard to document, confusing to explain, and I've never seen a case where it really simplifies things.

If you really need to export a simple procedural interface, create an object and export curried functions that use the object to call the methods.

  • Comment on Re^2: converting libraries into modules

Replies are listed 'Best First'.
Re^3: converting libraries into modules
by Limbic~Region (Chancellor) on Mar 05, 2006 at 22:34 UTC
    chromatic,
    While I tend to agree that having single functions that works as a method and an exportable function is usually a bad idea, your solution seems a bit over the OP's head. Would you mind providing a code sample, point to an existing wheel, or link to some documentation that does a better job explaining.

    For what it is worth - I really like that Perl6 will distinguish between methods and subs as well as provide multi-method dispatch.

    Cheers - L~R

      It could be as simple as:

      use vars '@EXPORT'; @EXPORT = qw( list of methods to curry ); sub import { my $class = shift; my $curried_object = $class->new(); my $caller = caller(); for my $export ( @EXPORT ) { *{ $caller . "::$export" } = sub { $curried_object->$export( @ +_ ) }; } }
        I like this one, it's very clever and it will even work with InsideOut or closure objects, that's great :)