Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: call a modules INIT-section (fix for Win32::API::Type)

by ihb (Deacon)
on Mar 20, 2005 at 12:45 UTC ( #441009=note: print w/ replies, xml ) Need Help??


in reply to call a modules INIT-section

I took a glance at Win32::API::Type which is the module that uses INIT. It seems like the author has misunderstood the purpose of INIT blocks. There's no need for the code to execute at INIT time. With some hackery you can work around this. The idea goes like this: add an INC hook that if Win32::API::Type gets used it locates the file it wants to use, reads the file, removes the INIT, opens a filehandle to the modified source and returns the filehandle. Code-wise it can look like

use 5.008; use File::Slurp qw/ read_file /; unshift @INC => sub { return undef unless $_[1] eq 'Win32/API/Type.pm'; my $f = your_favourite_module_locate_routine(...); my $src = read_file($f); $src =~ s/INIT (?={)//; open my $fh, '<', \$src or die "I have no idea if or why this would ever die, but anyw +ay: $!"; return $fh; };
As for locating which file to load there's a number of modules on CPAN that does that.

ihb

See perltoc if you don't know which perldoc to read!


Comment on Re: call a modules INIT-section (fix for Win32::API::Type)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://441009]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2014-11-26 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (162 votes), past polls