NAME
WWW::Wikipedia - Automated interface to the Wikipedia
SYNOPSIS
use WWW::Wikipedia;
my $wiki = WWW::Wikipedia->new();
## search for 'perl'
my $result = $wiki->search( 'perl' );
## if the entry has some text print it out
if ( $result->text() ) {
print $result->text();
}
## list any related items we can look up
print join( "\n", $result->related() );
DESCRIPTION
WWW::Wikipedia provides an automated interface to the Wikipedia http://www.wikipedia.org, which is a free, collaborative, online encyclopedia. This module allows you to search for a topic and return the resulting entry. It also gives you access to related topics which are also available via the Wikipedia for that entry.
METHODS
new()
The constructor, which ordinarily takes no arguments.
my $wiki = WWW::Wikipedia->new();
WWW::Wikipedia uses LWP::UserAgent to to talk to the Wikipedia. If you would like to have more control over the user agent (control timeouts, proxies ...) you can pass in a user agent for WWW::Wikipedia to use.
my $ua = LWP::UserAgent->new();
$ua->timeout( 2 );
my $wiki = WWW::Wikipedia->new( ua => $ua );
search()
Which performs the search and returns a WWW::Wikipedia::Entry object which you can query further.
$entry = $wiki->search( 'Perl' );
text()
After you have performed a search you use text() to retrieve the text of the entry. If your search failed you will be returned undef
.
$entry = $wiki->search( 'Perl' );
print "Perl is: ",$entry->text();
related()
related() returns a list of wiki items that are related to the entry in question. You can use these terms as possible new searches. If there are no realted items you get back an empty list.
$entry = $wiki->search( 'Perl' );
foreach ( $wiki->related() ) {
print "$_\n";
}
## which prints out this:
1987
2002
Acronym
Artistic License
Awk
Backronym
C programming language
CPAN
Common Gateway Interface
Free software movement
Functional programming
GPL
Java programming language
Larry Wall
Microsoft Windows
Obfuscated code
Object Oriented Programming
Operating system
Parrot virtual machine
Poetry
Procedural programming
Programming language
Regular expression
Scripting programming languages
Sed
Sh
Syntax
Unicode
Unix
Unix-like
Virtual machine
Wikipedia
TODO
Clean up results
Support for other language Wikipedias
Handle failed searches by suggesting other entries?
SEE ALSO
HTML::Parser
LWP::UserAgent
AUTHOR
Ed Summers, <esummers@flr.follett.com>
COPYRIGHT AND LICENSE
Copyright 2003 by Ed Summers
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.