Perl goodies
by Mike Blazer

Well, not too much goodies at this time ;-)
But I expect to add some useful samples soon.
And design... Oh-h, later... may be.

Win32::DUN.pm

      This little module provides few methods to check DialUp entries, to dial, to hang up, to autodial with manual confirmation or without, to autodial random provider from your list. It's kinda perl wraper of nice Win95/NT console application rasdial.exe by Claudio Fahey that is wide spread in freeware archives on the net. I also included it into the full package. .


Win32::Registry.pm is needed.


Win32::DUN.pm v.0.02

Readme.txt

Win32_DUN-0.02.pm.zip

Testing connection

      These are somehow related problems - testing whether you are online or not and detecting current domain-name/ip-address.
      I'll try to make short summary here.
      Old good chat2.php by Randal Schwartz offers:

chop($thishost = `hostname`);


      AFAIK this returns current ip-address on UNIX and NT machines but not on Win95 unless you have for example cygwin32 tools with hostname.exe installed.
      The other solution that works on Win95 also (I found it somewhere in comp.lang.perl.* conferences):

 ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname ("localhost"); ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname ($name); $thishost= join '.', unpack ('C4', $addrs[0]); 

      Or in the form of subroutine that returns both - current host-name and ip-address:

 #========================= sub GetLocalAddr { #========================= # returns local hostname, ip-address    my ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname ("localhost");    ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname ($name);    ((gethostbyaddr $addrs[0], 2)[0], join '.', unpack 'C4', $addrs[0]); } 

      OK. This subroutine returns undef if offline, so the easiest way to detect connection would be:

 #========================= sub CheckConnect { #========================= # returns 1/0 if connected/disconnected    (gethostbyname ((gethostbyname ("localhost"))[0]))[0] ? 1 : 0; } 

      This is just shortened GetLocalAddr.
      I experienced some problem with this subroutine. It detects on/offline well while used alone. But after some real up/download and disconnection it freezes until new connection will be established. So, this is not good for automated projects.
NOTE: Some times ago Aldo Calpini gave his version of the same routine that will detect the situation when the computer has more then one ip-address:

 sub GetIPs {     my @ips;     my($name,$aliases,$addrtype,$length,@addrs) = gethostbyname('localhost');     ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($name);     foreach $addr (@addrs) {         push(@ips, join(".", unpack("C4", $addr)));     }     return @ips; }

      Next sample is what I used in my Win32::DUN.pm. That CheckConnect routine uses external Win32 console application rasdial.exe and gives valuable answer only to detect offline. But if any DialUp session is in progress it can't detect whether connection is already established or not.
      Usage:

 use Win32::DUN; $entry=Win32::DUN::CheckConnect(); if ($entry) { print "Connected or dialing to $entry.\n"; } else {      print "Disconnected.\n"; } 

      The last solution is to establish socket connection with some trusted service, say Microsoft or Yahoo. There is more then one way... ;)
      Here is one working sample that uses Randal Schwartz's chat2.php (with few modifications it works on Win95 also):

 #========================= sub CheckConnect { #========================= # returns 1/0 if connected/disconnected    require "chat2.php";     if (&chat::open_port('www.yahoo.com', 80)) {        &chat::close(); return 1;    } else { return 0 } } 

      To my experience this is the best one to detect connection. It works very stable without any delays. But sure I'd not say that this is a clean solution. Again, I hope Aldo or somebody will port native Win32 API calls for this case too.

Win32::LFN.pm

      Win32::GetShortPathName that comes with current Win32 ports of Perl 5 provides the conversion from Long File Names (LFN) to DOS-style short names. The idea of this module was to provide backward conversion.
In addition it gives full attributes set for file/directory.

The module is completelly rewritten to improve speed and to match the changes in core Perl. Perl 5.006 and ActiveState port as of build 514 include new built-in functions
Win32::GetLongPathName() and Win32::GetFullPathName(). So, this version of Win32::LFN is probably the last and is intended for those who use older perl ports.

The module now has the functions with the same names and functionality:
Win32::LFN::GetLongPathName() and Win32::LFN::GetFullPathName(). The old functions still remain for the backward compartibility but they are also rewritten using much faster API call.

Win32::API.pm by Aldo Calpini is needed.


Win32::LFN.pm v.0.05

Manpage

Win32_LFN_0.05.zip

Ru::Text.pm

      This module provides some basic conversions of russian text in various encodings. It replaces default functionality of uc, lc, ucfirst, lcfirst to work with russian letters too (in chosen encoding) and builds few methods for regular expressions to make life easier.

      It is possible to change encoding-mode and work with few different encodings in the same program.

      ALT, windows-1251, windows-1251, windows-1251, MAC (Cyrillic) codepages are supported now.

      Perl 5.000 or better and Tie::Scalar.pm are needed.

NOTE: Please, don't distribute this module as plain text - by mail or by Copy/Paste from browser or editor. It contains binary data that will definitely be corrupted.


Ru::Text.pm v.0.01    <-- DON'T COPY/PASTE MODULE FROM HERE

Manpage

Ru-Text-0.01.zip

Win32::DriveInfo.pm

      With this module you can get total/free space on Win32 drives, volume names, architecture, filesystem type, drive attributes, list of all available drives and free drive-letters. Additional function to determine Windows version info.

      Win32::API.pm by Aldo Calpini is needed.


Win32::DriveInfo.pm v.0.03

Readme

Manpage

Win32_DriveInfo_0.03.zip

Net::NetTime.pm v.0.02

      With this module you can get current time from SNTP-servers(rfc1769) and TIME-servers(rfc868) via UDP or TCP. Time is returning in the form of the версия для печати time() function. It's designed for the faster and most stable delivery of time for both core Perl and Win32-Perl applications.

      Timeouts are semi-functional even on Win32, so it seems much that you application will not wait forever. In most cases it works really fast.

      Module is in early development stage.

      Updated chat2.php is included to the distribution.


Net::NetTime.pm v.0.02

Readme

Net_NetTime_0.02.zip

Win32::Process.pm v.0.061

      This is v.0.06 that comes with the libwin-0.15 (or 0.151) with few small additions. New version is fully backward compartible.
      Now you can open child window minimized, that is handy for GUI, or maximized that is handy for Win32::Console, Norton Commander, FAR and other interfaces.
      The other additional option is to open new console with the customized title instead of "PERL".
      Also one handy constant STILL_ACTIVE is added that helps monitoring exitcode in base parent cycle. For those of you who ever wondered what's that magic value - 259: it's STILL_ACTIVE status code (equal to STATUS_PENDING).

      For more take a look at the POD docs and Win32API docs.

      Binaries are also available, but note - GSAR version is compiled on Win95. As of 0.06 the same dll seem to work on both Win95 and NT but this fact has not been confirmed. ActiveState binaries for 5xx builds are compiled on NT (thanks to Jenda Krynicky!)

      If you want much more control on processes take a look at Win32::IProc by Amine Moulay Ramdane.

NOTE: As of 0.06 the parent process can get child's pid as unsigned long with the use of
GetProcessID() function. But $$ magic var returns pid as signed long, 32 bits both. The conversion rule is:

$unsigned_pid = unpack "L",pack "l",$$;




Manpage

Win32-Process-0.061.zip (sources)

Win32-Process-0.061_bin_GSAR.zip (binaries for GSAR port)

Win32-Process-0.061_bin_AS5xx.zip (binaries for ActiveState 5xx builds)

Win32::File::Ver.pm v.0.02

      This module extracts version information from the specified version-information resource of a binary file.

      This module requires:

Win32::API module by Aldo Calpini.
enum.pm (1.014 or later, no compilations) by Byron Brummer (aka Zenin)



Manpage

Win32::File::Ver.pm v.0.02

Win32_File_Ver_0.02.zip

Win32::Clock.pm v.0.01

      This module provides methods to get/set Win32 system clock with 0.01 s precision and also provides Win32 TimeZone information in a friendly form.

      It contains also a usefull function that should be moved later to some other package -
Unicode2ANSI().

      This module requires:

Win32::API module by Aldo Calpini.



Manpage

Win32::Clock.pm v.0.01

Win32_Clock_0.01.zip

Win32::RASE.pm v.1.00

      This module implements the client part of Win32 RAS API. It provides methods for creating, changing, managing RAS-phonebook/DialUp-Networking entries, managing user's credentials, dialing, hang-up, monitoring the connection status and dinamically assigned IP addresses. This module also provides an access to some TAPI related stuff - enumerating country codes, remote access devices, managing locations.

      There still is some lack of high-level functions like autodialing and some others that were implemented in Win32::DUN. But Win32::RASE is the correct way to do dial-up related things and Win32::DUN is now considered to be obsoletted.

      Look at the really huge POD docs for the complete explanations and use examples.php for quick start.

      The tarball distribution is prepared to be installed in a usual CPAN-compliant manner.

      This module requires:

Win32::API module by Aldo Calpini.
enum.pm (1.014 or later, no compilations) by Byron Brummer (aka Zenin)
Time::HiRes (0.18 or later) by Douglas E. Wegscheid makes work more precise.



Manpage

Win32::RASE.pm v.1.00

Win32_RASE_1.00.tar.gz

Win32::FFI::BrowseForFolder.pm v.0.02

      This module implements BrowseForFolder dialog on Win32 with the convenient callbacks making possible to change everything that could be changed. Well, almost ;-)
      The working FFI module by Paul Moore is needed for this module to work. It's somewhat close to Win32::API but it allows to create the callback functions, uses Perl's native way of loading libraries (as DynaLoader does) and even makes possible to call functions from the C runtime libraries.
      You should have MSVC++ to build it's underlying engine written in assembler. Although I managed to do this with Borland 5.02 but with the failures on some tests (not important for FFI) and with a lot of work.
      For brave men only! ;-)
      Note that if you just want a simple default view you should better use Win32::FileOp module that provides lots more features other then browsing for folder.



Manpage

Win32::FFI::BrowseForFolder.pm v.0.02

Win32_FFI_BrowseForFolder_0.02.zip


POD2HTML shell extension for Win32 v.0.01

      This small package will add "POD to HTML" option to the mouse right-click menu for .pm and .pod files. After that you'll be able to make <module-file-name>.html in the same directory with just two clicks.
And your .php, .phpx, .cgi, .pm, .pod files will have icons like this:
pl.ico plx.ico pm.ico pod.ico cgi.ico

Have some better icons? You are always welcome!

You'll probably have to restart Windows for these new settings to take effect.

You'll need my Win32::LFN module for this shell extension to run unless your perl has
Win32::GetLongPathName built-in function (ActiveState ActivePerl after build 514 or new 5.6 release).

Note: this shell extension is based on the new p2h_auto.bat file that is being installed to you <perl>/bin. It has to be in the PATH. So, if you have few perls on your system changing the default by changing PATH env. var. - you probably better copy p2h_auto.bat to <other-perl>/bin also.


Readme

pod2html_shellext_0.01.zip


Any comments and corrections are much appreciated!





Most of the samples are tested on the 'native' Win32 port of Perl 5.004_02 by Gurusamy Sarathy.

Last modified: February 27, 2000