Here is an outline of how to make Win32::API much easier to use. It results in code like:
use Win32::API qw( CreateIoCompletionPort N kernel32 N N N N ); use Win32::API qw( ... ); # ... my $hIOCP= CreateIoCompletionPort( $hSocket, 0, 0, 0 ); # ...
which is much nicer than how I've used Win32::API. Of course, support for more DWIM argument types is also in order, but I think I've seen such work underway elsewhere. (In fact, I'd probably allow for a code ref as an argument specification...)
Here is how simple this improvement is to implement:
sub Win32::API::import { my( $class, $sub, $ret, $lib, @args )= @_; my( $pkg )= (caller 1)[3]; my $obj = $class->new( $lib, $sub, [@args], $ret ) or croak( "Can't find $sub in $lib" ); no strict 'refs'; *{"$pkg::$sub"} = sub { $obj->Call( @_ ); }; }
Does this type of simplification come from thinking like "the users", or am I just strange? Does this seem like a huge improvement to others? Anyone else felt "from the beginning" that Win32::API should be creating code refs, like that was the "natural" interface to provide?
I often suspect that many code authors don't put much stress on the point of view of the users of their code. But I find that my view of the world (in so many respects) looks quite skewed to most people...
I'm sorry that this is such a skimpy node. I'm tied up with my day job but wanted to throw this idea out anyway...
- tye
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to make Win32::API easy to use
by BrowserUk (Patriarch) on Jun 02, 2004 at 19:42 UTC | |
by tye (Sage) on Jun 02, 2004 at 20:03 UTC | |
by BrowserUk (Patriarch) on Jun 02, 2004 at 20:13 UTC | |
by tye (Sage) on Jun 02, 2004 at 20:21 UTC | |
Re: How to make Win32::API easy to use
by demerphq (Chancellor) on Jun 02, 2004 at 20:33 UTC | |
by tye (Sage) on Jun 02, 2004 at 20:56 UTC | |
Re: How to make Win32::API easy to use
by dragonchild (Archbishop) on Jun 02, 2004 at 18:47 UTC | |
just alias import to Import
by PodMaster (Abbot) on Jun 03, 2004 at 00:05 UTC | |
Re: How to make Win32::API easy to use
by enoch (Chaplain) on Jun 02, 2004 at 20:42 UTC |