Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Win32: Shell extension for viewing POD (proof of concept)

by osfameron (Hermit)
on Oct 31, 2001 at 16:06 UTC ( [id://122327]=sourcecode: print w/replies, xml ) Need Help??
Category: Win32 Stuff
Author/Contact Info hakim@earthling.net
Description: We had an interesting chat about Shell extensions in WinNT in the Thread "Windows Drag and Drop".

I think that viewing POD from the Explorer window would be a useful use of Windows Shell extensions.

So this code is a) a wrapper around pod2html, and b) some instructions on how to create the Shell extensions.

As per Drag and Drop thread, I'd appreciate any clarification from a WinNT guru, but it works for me.

Proof of concept: please note all warnings in documentation

Update:v 0.002: Added an option to create a hyperlink to the source code the POD is taken from. You can switch this off by setting constant SOURCE=>0

use strict; use warnings;
use Win32; # Yes, this is a Win32 module: see POD
use HTML::Entities qw(encode_entities);

my $PERLBIN='c:\perl\bin';
use constant SOURCE=>1;

my $time=time;
my $file=$ARGV[0];
my $temp=$ENV{TEMP} || $ENV{TMP} || '.';


# 'cos we're being lazy and just redirecting HTML to a file
# I don't think we want to use array form of 'system'.  So
# I'm checking that the File is a genuine file and Temp is
# a genuine directory (e.g. this means that they can't contain
# any shell escapes).  Is this robust enough ?

unless ($file && -e $file) {
    $file ||="no file specified";
    my $error= "File doesn't exist! [$file] \n" ;
    Win32::MsgBox($error);
    die $error;
}
unless (-d $temp) {
    my $error= "Temp directory isn't a directory! [$temp] \n"; 
    Win32::MsgBox($error);
    die $error;
}

if (SOURCE) {
    open (FILE, $file) or die;
    my @file = <FILE>;
    close FILE or die;
    open (SRC,  ">$temp\\$time.src");
    open (SRCHTML,  ">$temp\\$time.src.html");
    # prepend source file with html instructions for viewing source
    print SRC qq(=begin html\n<a href="file://$temp/$time.src.html">Vi
+ew source</a>\n\n=cut\n\n);
    print SRCHTML <<EOF_HEAD;
<html>
<head><title>Source of $file</title></head>
<body>
<pre>
EOF_HEAD
    for (@file) { 
        print SRC $_;
        # encode_entities escapes any characters that might be
        # special in HTML
        print SRCHTML encode_entities($_);
    };
    print SRCHTML <<EOF_FOOT;
</pre>
</body></html> 
EOF_FOOT
    close SRC or die;
    close SRCHTML or die;
    $file="$temp\\$time.src";
}

system qq($PERLBIN\\pod2html $file --title="POD from $file" > $temp\\$
+time.html);
system qq(start $temp\\$time.html);
system "pause";

    

=head1 NAME

podview 

=head1 DESCRIPTION

A wrapper around the standard pod2html utility to view POD.

Following a thread on www.perlmonks.com about Drag and Drop for callin
+g Perl
scripts (which I think is a bad thing by the way) I thought this might
+ be a
better use of Windows NT Shell extensions to make WinNT more useful fo
+r Perl
programming.

(Not the other way round obviously).

If you implement the WinNT registry changes listed, you should be able
+ to 
right-click on a .pl, .pm or .pod file and choose a "View as HTML" opt
+ion.  
This B<should> open in your default browser.

=head1 WARNING

This is proof of concept.  It involves manually editing the registry. 
+ DON'T
DO THIS!

(I am only doing this because 

=over 4

=item *

I know why it's bad  (!)

=item *

I don't have anything too important on my Win2K box

=item *

I won't whinge at myself if it all goes 
wrong.

=back

For more warnings about how dangerous editing the registry is, try
www.microsoft.com)

=head1 HOW TO SET UP

I'm assuming that your perl is in C:\perl\bin\perl.exe.  If not please
+ edit the
variable in this script, and in the registry entries I mention.

=item 1

Save this script in C:\perl\bin as podview.pl

Note that you can now use the script as a wrapper around pod2html by c
+alling

     podview.pl {filename}

Where {filename} contains some POD.

=item 2

Open the registry. Then read again the warnings above.

 Go to 
     My Computer\HKEY_CLASSES_ROOT

 Make sure that keys exist for the following 

     .pl     Perl
     .pm     PerlModule
     .pod    POD

 I've suggested what I think could be values in the "Default" value.  
+But
 If you have different values already existing then another program (a
+ Perl
 IDE for example) may have registered them, so just make a note of wha
+t that
 value is.

 For each of the above values go to
     My Computer\HKEY_CLASSES_ROOT\{value}
 for example

     My Computer\HKEY_CLASSES_ROOT\Perl\Shell

 Notice that there is already a sub-key called "Open".  In Open there 
+is a 
 subkey called "Command".
 This has a value like:
     C:\Perl\bin\perl.exe "%1" %*

 This is the command that will be run when you double click on a Perl 
+script
 in the GUI, or you right-click on it and choose "Open".

 Under Shell, create a key called "View POD", and under that a key cal
+led 
 "Command" Now you have a key called

     My Computer\HKEY_CLASSES_ROOT\Perl\Shell\View POD\Command

 All we need to do is to add a command in here.  Double click on the d
+efault
 value and add the following

     C:\Perl\bin\perl.exe C:\Perl\bin\podview.pl "%1"

 We need to put %1 (the parameter - e.g. the name of the file being vi
+ewed
 in quotes in case the name has any spaces in it!)

=item 3

Now test: right click on a .pl, .pm or .pod file.  Do you have the C<V
+iew Pod>
option?  Choose it.  If it opens up your POD in a browser that's good.
If not something went wrong.  Check that you typed the Registry value 
+correctly
(I managed to type it wrong 3 times while testing).

=head1 AUTHOR, VERSION, ETC

hakim@earthling.net (osfameron on www.perlmonks.com / www.perlmonks.or
+g)

version 0.002

This is Proof Of Concept.  Use at your own risk: no warranty express o
+r
implied.

I cannot offer any support on this, but would welcome any comments.

=head1 BUGS

If the document has no POD a blank HTML document will be opened.

Did I mention that this was test code?  Let me know!

=cut
Replies are listed 'Best First'.
Re: Win32: Shell extension for viewing POD (proof of concept)
by Anonymous Monk on Sep 16, 2010 at 23:59 UTC
    I was just searching by Google perl win32 shell because I just migrate a software from a ActiveState Perl version from 1999.

    There is

    use Win32::Shell;

    with typical calls like

    Win32::Shell::Execute( "open", "bathfile.bat", "", ".\\", "SW_SHOWMAXIMIZED" ); Win32::Shell::Execute( "open", $path::convert, "$colors $geometry -interlace plane -comment \"Chevalier Roland Mösl\" $url::path_use.bmp $target", ".\\", "SW_HIDE" );

    opening batch files or other programms

    Now I need a actual version for this 11 years old module.

      Hi,
      I haven't managed to track it down. There's no Win32::Shell on cpan or backpan - according to the Win32-GUI-1.06 FAQ (as of June 2001) it was available only as a ppm package from ActiveState. That was probably the case back in June 2001, but it seems ActiveState no longer provides that ppm package. (If they do, I couldn't find it.)

      Presumably there's a recommendation as an alternative to Win32::Shell, but I don't know what that recommendation would be. Perhaps if you start a new thread here titled (something like) "What happened to Win32::Shell", you might attract the attention of someone who knows a bit more about it.

      Or, you could post to the perl-win32-users mailing list (which is hosted by ActiveState) and see if anyone there can help out.

      Cheers,
      Rob

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found