Ever since MetaCPAN launched I’ve been getting increasingly irritated with people who still use links to search.cpan.org. Isn’t it obvious that MetaCPAN is better? Why do people still insist on sharing links to the older site?
Of course they do it for various reasons. Perhaps they aren’t as in touch with the modern Perl world as I am. Perhaps they are wary about changing to use the new shiny toys because they know that a newer shinier one will be along soon. Perhaps I’m reading a web page from five years ago and they can be forgiven for not linking to a site that didn’t exist at the time.
Eventually I realised that there was no point in getting annoyed. I had a computer. Surely I could do something that would fix this problem.
My first idea was to write a GreaseMonkey script. Then I realised that would be hard. MetaCPAN and CPAN have slightly different URL schemes. I’d need to recognise a CPAN URL and convert it to the equivalent MetaCPAN URL. Not an impossible task at all, but not something I could knock up in an hour or so. Especially not in Javascript.
So I asked on the #metacpan IRC channel. Surely I couldn’t be the first person to have this problem. And someone there introduced me to mcpan.org. There’s no point in clicking on that link. You’ll just end up on MetaCPAN. Because that’s what mcpan does. It’s a URL rewriting service. You give it a CPAN URL (with the cpan.org changed to mcpan.org) and it redirects you to the equivalent page on MetaCPAN.
That’s the hard bit of the problem. The bit I didn’t want to write. And someone else has already written it. But they seem to have kept it very quiet. This deserves more publicity. I wish I could remember who wrote it. If you know, please leave a comment.
So we’re now most of the way there. Now if I click on a CPAN link, I can just edit the location bar to add an ‘m’ and I’ll be redirected to the right place. But we can do better than that. I’d like to be automatically redirected. That’s when I discovered the Redirector extension for Firefox. Once it’s installed you can configure it to redirect certain URLs to other ones. I have it configured so that http://search.cpan.org* redirects to http://mcpan.org$1. See how you can use wildcards to match URLs and then use whatever they matched in the replacement URL. It’s a lot like regexes in Perl.
And we’re done. Now whenever I click on an old-style CPAN link, I’m automatically redirected to mcpan, And that, in turn, redirects me to MetaCPAN. And, best of all, I didn’t have to write any code. It was just a case of putting together tools that already existed.
I did all this a few months ago. I meant to write this blog post at the time, but I forgot. I was reminded this morning when Chisel mentioned a GreaseMonkey script he had written to do all of this. See, Chisel isn’t afraid of parsing URLs in Javascript like I was. He just went ahead and did it.
But having alternative solutions to the problem is good, right?
Update: I’ve just been talking about this on the #metacpan IRC channel and it seems that I was rather misunderstanding what was going on here. Here are the details.
Firstly, it was dpetrov who told me about mcpan.org. It’s his domain. I asked him for the code, and he pointed out that there is no code. mcpan.org just redirects everything to a domain called sco.metacpan.org which is where the magic happens. He just got tired of editing search.cpan.org to sco.metacpan.org so he registered another, simpler, domain.
So the actual cleverness happens over on sco.metacpan.org. And that’s really just a list of rewrite rules (the code is on github). I say “just”, but I still wouldn’t want to write them myself.
All this means that mcpan,org is only a convenient tool for when you’re manually editing your location bar. When you’re using the Redirector extension for Firefox you can miss out the middle man and redirect straight to sco.metacpan.org. So I’ve updated my Redirector rule appropriately.
This is a great blog post and a wonderful discovery – it looks like I can massively simplify my userscript … maybe now I’m at the point where I just need to locate a Redirector plugin for Chrome
Hmm, the Fedora ‘cpanspec’ tool inserts the following type of http://search.cpan.org/dist/String-Random/ into all RPM specs. If metacpan.org is the preferred site, sounds like a bulk search-and-replace in Fedora RPM specs is needed & a fix to cpanspec.
I use it mostly when some google result point me to search.cpan.org and it’s really easy to switch 🙂
Thank you for this!
Now to find a way to use this together with the search.cpan.org search engine… my Greasemonkey script for that (description and rationale) takes a different tack that does not compose with this solution verbatim – you would just get redirected to the inferior MetaCPAN search. A solution that did both would be perfect.
Chrome extensions include “Redirector” and “Switcheroo”. Not tried either, but I have tried this javascript redirect (needs adjusting): http://superuser.com/a/284144/65611 which works most of the time (not looked into why it fails yet)
> Isn’t it obvious that MetaCPAN is better?
No it isn’t, because it isn’t. MetaCPAN does a lot of things much better, but there are still a number of issues where search results are flaky to useless, or metacpan just plain refuses to render the pod of modules that sco will show just fine.
I have always liked linking to the metacpan myself, for the “Reverse dependencies”.
But as Mr. Walde mentioned, sco has its use…I just don’t want to have to link to both.
I’ve always wondered why there isn’t a bi-directional link between the two sites.
I wish cpan would direct link to the metacpan, and I don’t understand why they don’t.
or I assume I’m missing it on the page.
nice site.
–dave
http://dave.thehorners.com/tech-talk/programming/94-perl-programming
Thanks for this 🙂