README
1NAME
2 WWW::Wikipedia - Automated interface to the Wikipedia
3
4SYNOPSIS
5 use WWW::Wikipedia;
6 my $wiki = WWW::Wikipedia->new();
7
8 ## search for 'perl'
9 my $result = $wiki->search( 'perl' );
10
11 ## if the entry has some text print it out
12 if ( $result->text() ) {
13 print $result->text();
14 }
15
16 ## list any related items we can look up
17 print join( "\n", $result->related() );
18
19DESCRIPTION
20 WWW::Wikipedia provides an automated interface to the Wikipedia
21 <http://www.wikipedia.org>, which is a free, collaborative, online
22 encyclopedia. This module allows you to search for a topic and return
23 the resulting entry. It also gives you access to related topics which
24 are also available via the Wikipedia for that entry.
25
26INSTALLATION
27 To install this module type the following:
28
29 perl Makefile.PL
30 make
31 make test
32 make install
33
34METHODS
35 new()
36 The constructor. You can pass it a two letter language code, or nothing
37 to let it default to 'en'.
38
39 ## Default: English
40 my $wiki = WWW::Wikipedia->new();
41
42 ## use the French wiki instead
43 my $wiki = WWW::Wikipedia->new( language => 'fr' );
44
45 WWW::Wikipedia is a subclass of LWP::UserAgent. If you would like to
46 have more control over the user agent (control timeouts, proxies ...)
47 you have full access.
48
49 ## set HTTP request timeout
50 my $wiki = WWW::Wikipedia->new();
51 $wiki->timeout( 2 );
52
53 You can turn off the following of wikipedia redirect directives by
54 passing a false value to "follow_redirects".
55
56 Together with the Wiki markup, some entries include HTML tags. They can
57 be stripped out using the "clean_html" option:
58
59 my $wiki = WWW::Wikipedia->new( clean_html => 1 );
60
61 See "clean_html" documentation below for details.
62
63 language()
64 This allows you to get and set the language you want to use. Two letter
65 language codes should be used. The default is 'en'.
66
67 my $wiki = WWW::Wikipedia->new( language => 'es' );
68
69 # Later on...
70 $wiki->language( 'fr' );
71
72 clean_html()
73 Allows you to get/set if HTML is being stripped out.
74
75 # set HTML strip
76 $wiki->clean_html( 1 );
77
78 This option removes all tags and attributes they might have. Their
79 contents, however, is maintained (for now). Comments are also removed.
80
81 follow_redirects()
82 By default, wikipeda redirect directives are followed. Set this to false
83 to turn that off.
84
85 search()
86 Which performs the search and returns a WWW::Wikipedia::Entry object
87 which you can query further. See WWW::Wikipedia::Entry docs for more
88 info.
89
90 $entry = $wiki->search( 'Perl' );
91 print $entry->text();
92
93 If there's a problem connecting to Wikipedia, "undef" will be returned
94 and the error message will be stored in "error()".
95
96 random()
97 This method fetches a random wikipedia page.
98
99 error()
100 This is a generic error accessor/mutator. You can retrieve any searching
101 error messages here.
102
103TODO
104 * Be more specific on the HTML clean methodology. For now all tags are
105 removed, keeping only their contents. In the future the behaviour
106 might change accordingly with each specific tag.
107
108 * Watch the development of Special:Export XML formatting, eg:
109 http://en.wikipedia.org/wiki/Special:Export/perl
110
111SEE ALSO
112 * LWP::UserAgent
113
114REPOSITORY
115 <https://github.com/edsu/www-wikipedia>
116
117AUTHORS
118 Ed Summers <ehs@pobox.com>
119
120 Brian Cassidy <bricas@cpan.org>
121
122COPYRIGHT AND LICENSE
123 Copyright 2003-2017 by Ed Summers
124
125 This library is free software; you can redistribute it and/or modify it
126 under the same terms as Perl itself.
127
128