Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

($code or die) Re: Repository code (HowTo build and distribute a PPMed module for Win32)

by $code or die (Deacon)
on Sep 25, 2001 at 18:39 UTC ( #114544=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: Re: HowTo build and distribute a PPMed module for Win32
in thread HowTo build and distribute a PPMed module for Win32

Right, I have been re-reading and understand how the search command works.

When you do search Module-Name, it run's the function list_available(). This function returns a list of .ppd files in the repository. It does it differently depending on what type of repository it is, e.g.: file://, UNC, SOAP, or http://. We're interested in the last bit of the function concerning http.

If the repository is an http:// repository (not soap), then it calls the function read_href() which returns the text on the page. list_available() expects either a directory listing (Apache or IIS format) or a default.prk format file - ActiveState's Visual Package Manager that's part of the Perl Dev Kit.

For the search to work properly (without implimenting a SOAP interface or .prk) your repository must return something that resembles a directory listing, which parses.

Thankfully, keeps the "libwww-perl/" part of the user agent. So we can write a small script that will return a directory listing for ppm and a nicely formatted page for regular browsers. This is a small working example of what to do:
use strict; use CGI qw( :all ); my $user_agent = user_agent(); my $html_redirection = ''; if ($user_agent =~ m#libwww-perl/#) { # it's a perl bot - probably ppm, so return a # compatible directory listing print_dir_listing(); } else { # it's probably a regular browser, redirect... print redirect(-uri => $html_redirection); } sub print_dir_listing { # Get the current directory, (cwd doesn't necessarily work in IIS) (my $cwd = $0) =~ s[\\][/]g; $cwd =~ s[/([^/]*)$][]; print header({-type => "text/plain"}); opendir FOLDER, $cwd or die "I don't have permission $!"; print a({-href => $_}, $_ ), "\n" for grep { /\.ppd$/ } readdir FO +LDER; closedir FOLDER; }
Save this to or something and make sure it's the default document. Then change $html_redirection variable to the URL where you want your actual users to go to and you're set. You can of course do something more dynamic for the actual users page, such as parse the XML in the PPD files to give user's full information on the modules (version, description, author etc) without having to edit an html file every time you change a package or add a new one. I leave that as an exercise for the reader :)

Simon Flack ($code or die)
$,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
=~y'_"' ';eval"die";print $_,lc substr$@,0,3;
  • Comment on ($code or die) Re: Repository code (HowTo build and distribute a PPMed module for Win32)
  • Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://114544]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2017-07-23 18:51 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (347 votes). Check out past polls.