Skip Menu |

This queue is for tickets about the Win32-API CPAN distribution.

Report information
The Basics
Id: 14345
Status: resolved
Worked: 15 min
Priority: 0/
Queue: Win32-API

People
Owner: cosimo [...] cpan.org
Requestors: jdhedden [...] 1979.usna.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: INIT block not executed in Win32::API::Type when 'require' used
INIT blocks do not get executed when modules are imported using 'require': Too late to run INIT block at C:/perl5/site/5.8.7/lib/MSWin32-x86-multi-thread/Win32/API/Type.pm line 71. This is a significant problem for modules that want to optionally support Win32 features. The INIT block and __DATA__ section should be replaced by coding in the data directly. I have attached a patch to do this.
--- Type.pm 2005-08-28 10:35:29.013750000 -0400 +++ Type-new.pm 2005-08-28 10:57:24.576250000 -0400 @@ -31,44 +31,165 @@ } } -%Known = (); -%PackSize = (); -%Modifier = (); -%Pointer = (); - -INIT { - my $section = 'nothing'; - foreach (<DATA>) { - next if /^\s*#/ or /^\s*$/; - chomp; - if( /\[(.+)\]/) { - $section = $1; - next; - } - if($section eq 'TYPE') { - my($name, $packing) = split(/\s+/); - # DEBUG "(PM)Type::INIT: Known('$name') => '$packing'\n"; - $Known{$name} = $packing; - } elsif($section eq 'PACKSIZE') { - my($packing, $size) = split(/\s+/); - # DEBUG "(PM)Type::INIT: PackSize('$packing') => '$size'\n"; - $PackSize{$packing} = $size; - } elsif($section eq 'MODIFIER') { - my($modifier, $mapto) = split(/\s+/, $_, 2); - my %maps = (); - foreach my $item (split(/\s+/, $mapto)) { - my($k, $v) = split(/=/, $item); - $maps{$k} = $v; - } - # DEBUG "(PM)Type::INIT: Modifier('$modifier') => '%maps'\n"; - $Modifier{$modifier} = { %maps }; - } elsif($section eq 'POINTER') { - my($pointer, $pointto) = split(/\s+/); - # DEBUG "(PM)Type::INIT: Pointer('$pointer') => '$pointto'\n"; - $Pointer{$pointer} = $pointto; - } +%Known = ( + ATOM => 's', + BOOL => 'L', + BOOLEAN => 'c', + BYTE => 'C', + CHAR => 'c', + COLORREF => 'L', + DWORD => 'L', + DWORD32 => 'L', + DWORD64 => 'Q', + FLOAT => 'f', + HACCEL => 'L', + HANDLE => 'L', + HBITMAP => 'L', + HBRUSH => 'L', + HCOLORSPACE => 'L', + HCONV => 'L', + HCONVLIST => 'L', + HCURSOR => 'L', + HDC => 'L', + HDDEDATA => 'L', + HDESK => 'L', + HDROP => 'L', + HDWP => 'L', + HENHMETAFILE => 'L', + HFILE => 'L', + HFONT => 'L', + HGDIOBJ => 'L', + HGLOBAL => 'L', + HHOOK => 'L', + HICON => 'L', + HIMC => 'L', + HINSTANCE => 'L', + HKEY => 'L', + HKL => 'L', + HLOCAL => 'L', + HMENU => 'L', + HMETAFILE => 'L', + HMODULE => 'L', + HPALETTE => 'L', + HPEN => 'L', + HRGN => 'L', + HRSRC => 'L', + HSZ => 'L', + HWINSTA => 'L', + HWND => 'L', + INT => 'i', + INT32 => 'i', + INT64 => 'q', + LANGID => 's', + LCID => 'L', + LCSCSTYPE => 'L', + LCSGAMUTMATCH => 'L', + LCTYPE => 'L', + LONG => 'l', + LONG32 => 'l', + LONG64 => 'q', + LONGLONG => 'q', + LPARAM => 'L', + LRESULT => 'L', + REGSAM => 'L', + SC_HANDLE => 'L', + SC_LOCK => 'L', + SERVICE_STATUS_HANDLE => 'L', + SHORT => 's', + SIZE_T => 'L', + SSIZE_T => 'L', + TBYTE => 'c', + TCHAR => 'C', + UCHAR => 'C', + UINT => 'I', + UINT_PTR => 'L', + UINT32 => 'I', + UINT64 => 'Q', + ULONG => 'L', + ULONG32 => 'L', + ULONG64 => 'Q', + ULONGLONG => 'Q', + USHORT => 'S', + WCHAR => 'S', + WORD => 'S', + WPARAM => 'L', + VOID => 'c', + int => 'i', + long => 'l', + float => 'f', + double => 'd', + char => 'c' +); + +%PackSize = ( + c => 1, + C => 1, + d => 8, + f => 4, + i => 4, + I => 4, + l => 4, + L => 4, + q => 8, + Q => 8, + s => 2, + S => 2, + p => 4 +); + +%Modifier = ( + unsigned => { + 'int' => 'I', + 'long' => 'L', + 'short' => 'S', + 'char' => 'C' } -} +); + +%Pointer = ( + INT_PTR => 'INT', + LPBOOL => 'BOOL', + LPBYTE => 'BYTE', + LPCOLORREF => 'COLORREF', + LPCSTR => 'CHAR', + LPCTSTR => 'CHAR', + LPCVOID => 'any', + LPCWSTR => 'WCHAR', + LPDWORD => 'DWORD', + LPHANDLE => 'HANDLE', + LPINT => 'INT', + LPLONG => 'LONG', + LPSTR => 'CHAR', + LPTSTR => 'CHAR', + LPVOID => 'VOID', + LPWORD => 'WORD', + LPWSTR => 'WCHAR', + PBOOL => 'BOOL', + PBOOLEAN => 'BOOL', + PBYTE => 'BYTE', + PCHAR => 'CHAR', + PCSTR => 'CSTR', + PCWCH => 'CWCH', + PCWSTR => 'CWSTR', + PDWORD => 'DWORD', + PFLOAT => 'FLOAT', + PHANDLE => 'HANDLE', + PHKEY => 'HKEY', + PINT => 'INT', + PLCID => 'LCID', + PLONG => 'LONG', + PSHORT => 'SHORT', + PSTR => 'CHAR', + PTSTR => 'CHAR', + PUCHAR => 'UCHAR', + PUINT => 'UINT', + PULONG => 'ULONG', + PUSHORT => 'USHORT', + PVOID => 'VOID', + PWCHAR => 'WCHAR', + PWORD => 'WORD', + PWSTR => 'WCHAR' +); sub new { my $class = shift; @@ -263,178 +384,10 @@ This module should recognize all the types defined in the Win32 Platform SDK header files. -Please see the source for this module, in the C<__DATA__> section, -for the full list. +Please see the source for this module for the full list. =head1 AUTHOR Aldo Calpini ( I<dada@perl.it> ). =cut - - -__DATA__ - -[TYPE] -ATOM s -BOOL L -BOOLEAN c -BYTE C -CHAR c -COLORREF L -DWORD L -DWORD32 L -DWORD64 Q -FLOAT f -HACCEL L -HANDLE L -HBITMAP L -HBRUSH L -HCOLORSPACE L -HCONV L -HCONVLIST L -HCURSOR L -HDC L -HDDEDATA L -HDESK L -HDROP L -HDWP L -HENHMETAFILE L -HFILE L -HFONT L -HGDIOBJ L -HGLOBAL L -HHOOK L -HICON L -HIMC L -HINSTANCE L -HKEY L -HKL L -HLOCAL L -HMENU L -HMETAFILE L -HMODULE L -HPALETTE L -HPEN L -HRGN L -HRSRC L -HSZ L -HWINSTA L -HWND L -INT i -INT32 i -INT64 q -LANGID s -LCID L -LCSCSTYPE L -LCSGAMUTMATCH L -LCTYPE L -LONG l -LONG32 l -LONG64 q -LONGLONG q -LPARAM L -LRESULT L -REGSAM L -SC_HANDLE L -SC_LOCK L -SERVICE_STATUS_HANDLE L -SHORT s -SIZE_T L -SSIZE_T L -TBYTE c -TCHAR C -UCHAR C -UINT I -UINT_PTR L -UINT32 I -UINT64 Q -ULONG L -ULONG32 L -ULONG64 Q -ULONGLONG Q -USHORT S -WCHAR S -WORD S -WPARAM L -VOID c - -int i -long l -float f -double d -char c - -#CRITICAL_SECTION 24 -- a structure -#LUID ? 8 -- a structure -#VOID 0 -#CONST 4 -#FILE_SEGMENT_ELEMENT 8 -- a structure - -[PACKSIZE] -c 1 -C 1 -d 8 -f 4 -i 4 -I 4 -l 4 -L 4 -q 8 -Q 8 -s 2 -S 2 -p 4 - -[MODIFIER] -unsigned int=I long=L short=S char=C - -[POINTER] -INT_PTR INT -LPBOOL BOOL -LPBYTE BYTE -LPCOLORREF COLORREF -LPCSTR CHAR -#LPCTSTR CHAR or WCHAR -LPCTSTR CHAR -LPCVOID any -LPCWSTR WCHAR -LPDWORD DWORD -LPHANDLE HANDLE -LPINT INT -LPLONG LONG -LPSTR CHAR -#LPTSTR CHAR or WCHAR -LPTSTR CHAR -LPVOID VOID -LPWORD WORD -LPWSTR WCHAR - -PBOOL BOOL -PBOOLEAN BOOL -PBYTE BYTE -PCHAR CHAR -PCSTR CSTR -PCWCH CWCH -PCWSTR CWSTR -PDWORD DWORD -PFLOAT FLOAT -PHANDLE HANDLE -PHKEY HKEY -PINT INT -PLCID LCID -PLONG LONG -PSHORT SHORT -PSTR CHAR -#PTBYTE TBYTE -- -#PTCHAR TCHAR -- -#PTSTR CHAR or WCHAR -PTSTR CHAR -PUCHAR UCHAR -PUINT UINT -PULONG ULONG -PUSHORT USHORT -PVOID VOID -PWCHAR WCHAR -PWORD WORD -PWSTR WCHAR
Hello JD, it's been a long time, eh? ;-) The INIT block is now gone, as you already know, in v0.45. I think also data *DATA filehandle could be removed, but Aldo didn't agree with that. Can you confirm that the DATA fh gives you problems? Thanks for your patience.