Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Win32: Shell extension for viewing POD (proof of concept) by osfameron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found