File Coverage

blib/lib/Pod/Perldocs.pm
Criterion Covered Total %
statement 12 59 20.3
branch 0 18 0.0
condition 0 6 0.0
subroutine 4 9 44.4
pod 0 4 0.0
total 16 96 16.6


line stmt bran cond sub pod time code
1             package Pod::Perldocs;
2 1     1   26186 use strict;
  1         2  
  1         31  
3 1     1   6 use warnings;
  1         2  
  1         32  
4             require Pod::Perldoc;
5 1     1   446423 use LWP::UserAgent;
  1         2252029  
  1         41  
6 1     1   12 use base qw(Pod::Perldoc);
  1         2  
  1         783  
7             our ($VERSION);
8             $VERSION = '0.17';
9              
10             ################################################################
11             # Change the following to reflect your setup
12             my $soap_uri = 'http://theoryx5.uwinnipeg.ca/Apache/DocServer';
13             my $soap_proxy = 'http://theoryx5.uwinnipeg.ca/cgi-bin/docserver.cgi';
14             my $pod_server = q{http://cpan.uwinnipeg.ca/cgi-bin/podserver.cgi};
15             ###############################################################
16              
17             sub grand_search_init {
18 0     0 0   my($self, $pages, @found) = @_;
19 0           @found = $self->SUPER::grand_search_init($pages, @found);
20 0 0         return @found if @found;
21 0           print STDERR "Searching on remote pod server ...\n";
22 0           my $filename;
23 0 0         if ($filename = get_lwp($self, $pages->[0])) {
    0          
24 0           push @found, $filename;
25 0           return @found;
26             }
27             elsif ($filename = get_soap($self, $pages->[0])) {
28 0           push @found, $filename;
29 0           return @found;
30             }
31             else {
32 0           return @found;
33             }
34             }
35              
36             sub get_lwp {
37 0     0 0   my ($self, $mod) = @_;
38 0           my $ua = LWP::UserAgent->new;
39 0           $ua->agent("Pod/Perldocs 0.16 ");
40 0           push @{ $ua->requests_redirectable }, 'POST';
  0            
41             # Create a request
42 0           my $req = HTTP::Request->new(POST => $pod_server);
43 0           $req->content_type('application/x-www-form-urlencoded');
44 0           $req->content("mod=$mod");
45             # Pass request to the user agent and get a response back
46 0           my $res = $ua->request($req);
47             # Check the outcome of the response
48 0 0         if ($res->is_success) {
49 0           my ($fh, $filename) = $self->new_tempfile();
50 0           print $fh $res->content;
51 0           return $filename;
52             }
53             else {
54 0           print STDERR "Remote server returned status code: " . $res->status_line . "\n";
55 0           return;
56             }
57             }
58              
59             sub get_soap {
60 0     0 0   my ($self, $mod) = @_;
61 0 0         my $soap = make_soap() or return; # no SOAP::Lite available
62 0           my $result = $soap->get_doc($mod);
63 0 0 0       defined $result && defined $result->result or do {
64 0           print STDERR "No matches found there either.\n";
65 0           return;
66             };
67 0           my $lines = $result->result();
68 0 0 0       unless ($lines and ref($lines) eq 'ARRAY') {
69 0           print STDERR "Documentation not found there either.\n";
70 0           return;
71             }
72 0           my ($fh, $filename) = $self->new_tempfile();
73 0           print $fh @$lines;
74 0           return $filename;
75             }
76              
77             sub make_soap {
78 0 0   0 0   unless (eval { require SOAP::Lite }) {
  0            
79 0           print STDERR "SOAP::Lite is unavailable to make remote call\n";
80 0           return undef;
81             }
82              
83             return SOAP::Lite
84             ->uri($soap_uri)
85             ->proxy($soap_proxy,
86             options => {compress_threshold => 10000})
87 0     0     ->on_fault(sub { my($soap, $res) = @_;
88 0 0         print STDERR "SOAP Fault: ",
89             (ref $res ? $res->faultstring
90             : $soap->transport->status),
91             "\n";
92 0           return undef;
93 0           });
94             }
95              
96             1;
97              
98             =head1 NAME
99              
100             Pod::Perldocs - view remote pod via Pod::Perldoc
101              
102             =head1 DESCRIPTION
103              
104             This is a drop-in replacement for C based on
105             C. Usage is the same, except in the case
106             when documentation for a module cannot be found on the
107             local machine, in which case a query (via LWP or SOAP::Lite) will
108             be made to a remote pod repository and, if the documentation is
109             found there, the results will be displayed as usual.
110              
111             =head1 NOTE
112              
113             The values of C<$pod_server>, C<$soap_uri> and
114             C<$soap_proxy> at the top of this script reflect
115             the location of the remote pod repository.
116              
117             =head1 SERVER
118              
119             See the I project on SourceForge at
120             L
121             for the software needed to set up a remote pod
122             repository used by C.
123              
124             =head1 SEE ALSO
125              
126             L.
127              
128             =head1 COPYRIGHT
129              
130             This software is copyright 2004,2009 by Randy Kobes
131             Er.kobes@uwinnipeg.caE. Usage and redistribution
132             is under the same terms as Perl itself.
133              
134             =head1 CURRENT MAINTAINER
135              
136             Kenichi Ishigaki Eishigaki@cpan.orgE
137              
138             =cut