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
In reply to How to make Win32::API easy to use by tye
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |