Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by ihb (Deacon)
on Mar 20, 2005 at 12:45 UTC ( [id://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!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-28 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found