Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Syntactic Confectionary Delight
 
PerlMonks

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

by osfameron (Hermit)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

on Oct 31, 2001 at 16:06 UTC ( #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

Comment on Win32: Shell extension for viewing POD (proof of concept)
Download Code

Back to Code Catacombs

Login:
Password
remember me
What's my password?
Create A New User

Node Status
node history
Node Type: sourcecode [id://122327]
help
Community Ads
Chatterbox
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users
Others imbibing at the Monastery: (7)
GrandFather
wfsp
herveus
Spooty
Eyck
gnosti
im2
As of 2009-11-21 09:12 GMT
Sections
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Perl News
Information
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth

Future historians will find that the material characteristic of the current era is...

Aluminium
Plastic
Oil
Water
Carbon dioxide
Copper
Iron
Silicon
Salt
Uranium
Hydrogen
Other

Results (729 votes), past polls