My development is split between Windows XP and Linux. Even on Windows, I do most of my programming from the command-line. Recently, I thought it would be nice to launch a browser with a query to [http://search.cpan.org] straight from the command line:
> searchcpan Class::InsideOut
I also adapted the pseudo-URL style from perlmonks:
> searchcpan mod://Storable > searchcpan dist://Test-Simple > searchcpan author://dagolden
To get this working, I installed the following simple code as C:\perl\bin\searchcpan.pl and then ran pl2bat searchcpan.pl in that directory.
# searchcpan.pl
use strict;
use warnings;
my %modes = (
"mod://" => "module",
"dist://" => "dist",
"author://" => "author",
);
my $url = "http://search.cpan.org/search?query=QUERY;mode=MODE";
my $target = shift;
if ( ! $target ) {
$url =~ s{/search\?.+}{};
}
else {
my ($mode) = grep { $target =~ qr/\A$_/ } keys %modes;
if ( defined $mode ) {
$target =~ s{\A$mode}{};
$url =~ s{MODE}{$modes{$mode}};
$url =~ s{QUERY}{$target};
}
else {
$url =~ s{QUERY}{$target};
$url =~ s{MODE}{all};
}
}
system('C:\windows\system32\cmd.exe', "/C start $url" );
-xdg
Code written by xdg and posted on PerlMonks is [http://creativecommons.org/licenses/publicdomain|public domain]. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
Slightly off topic, but maybe interesting to somebody....
There is a script out there somewhere that uses AS "perlscript" and IE to make the AS docs interactively searchable. I dont recall much more than that, but it was a nifty tool, and a good example of how you can use IE/web as a presentation engine for Perl. No web server needed, just AS and IE.
I agree that's a neat idea, launching a browser window to display search results. I wonder if you could provide an alternative launch mechanism that would work with *nix as well, dependent on $^O. Reusing an existing browser instance and possibly opening in a new tab would be nice :).
Also, some other ideas spring to mind, like a dependency checker that opens browser windows for all the modules that you need, but don't yet have installed.
--
Oh Lord, wont you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, wont you burn me a Knoppix CD ?
(Missquoting Janis Joplin)
my $linkurl = 'http://zentara.net';
my $command = "mozilla -remote \"openURL($linkurl)\"";
if(fork() == 0){ exec ($command) }
Yeah, the cheater bit I used for Windows is the start command that dispatches the URL to the user-configured browser. I suspect there's an equivalent in Gnome/KDE (though I don't remember offhand). Unfortunately, without hard-coding a browser, I suspect this is both OS and X-environment specific on Unix. And I have no idea about MacOSX, though I suspect there's a similar "launch-url" command somewhere.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
www-browser (/usr/bin/w3m)
mozilla (
+ 1 /usr/bin/mozilla-suite
* 2 /usr/bin/mozilla-firefox
)
x-www-browser (
1 /usr/bin/mozilla
2 /usr/bin/epiphany
+ 3 /usr/bin/konqueror
* 4 /usr/bin/mozilla-firefox
)
So either mozilla or x-www-browser seem like sensible "launch-url" commands.
perlmonks.org content © perlmonks.org and demerphq, PodMaster, rhesa, rinceWind, xdg, zentara
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03