1LWP::Protocol(3)      User Contributed Perl Documentation     LWP::Protocol(3)
2
3
4

NAME

6       LWP::Protocol - Base class for LWP protocols
7

SYNOPSIS

9        package LWP::Protocol::foo;
10        require LWP::Protocol;
11        @ISA=qw(LWP::Protocol);
12

DESCRIPTION

14       This class is used a the base class for all protocol implementations
15       supported by the LWP library.
16
17       When creating an instance of this class using
18       "LWP::Protocol::create($url)", and you get an initialised subclass
19       appropriate for that access method. In other words, the
20       LWP::Protocol::create() function calls the constructor for one of its
21       subclasses.
22
23       All derived LWP::Protocol classes need to override the request() method
24       which is used to service a request. The overridden method can make use
25       of the collect() function to collect together chunks of data as it is
26       received.
27
28       The following methods and functions are provided:
29
30       $prot = LWP::Protocol->new()
31           The LWP::Protocol constructor is inherited by subclasses. As this
32           is a virtual base class this method should not be called directly.
33
34       $prot = LWP::Protocol::create($scheme)
35           Create an object of the class implementing the protocol to handle
36           the given scheme. This is a function, not a method. It is more an
37           object factory than a constructor. This is the function user agents
38           should use to access protocols.
39
40       $class = LWP::Protocol::implementor($scheme, [$class])
41           Get and/or set implementor class for a scheme.  Returns '' if the
42           specified scheme is not supported.
43
44       $prot->request(...)
45            $response = $protocol->request($request, $proxy, undef);
46            $response = $protocol->request($request, $proxy, '/tmp/sss');
47            $response = $protocol->request($request, $proxy, \&callback, 1024);
48
49           Dispatches a request over the protocol, and returns a response
50           object. This method needs to be overridden in subclasses.  Refer to
51           LWP::UserAgent for description of the arguments.
52
53       $prot->collect($arg, $response, $collector)
54           Called to collect the content of a request, and process it
55           appropriately into a scalar, file, or by calling a callback.  If
56           $arg is undefined, then the content is stored within the $response.
57           If $arg is a simple scalar, then $arg is interpreted as a file name
58           and the content is written to this file.  If $arg is a reference to
59           a routine, then content is passed to this routine.
60
61           The $collector is a routine that will be called and which is
62           responsible for returning pieces (as ref to scalar) of the content
63           to process.  The $collector signals EOF by returning a reference to
64           an empty sting.
65
66           The return value from collect() is the $response object reference.
67
68           Note: We will only use the callback or file argument if
69           $response->is_success().  This avoids sending content data for
70           redirects and authentication responses to the callback which would
71           be confusing.
72
73       $prot->collect_once($arg, $response, $content)
74           Can be called when the whole response content is available as
75           $content.  This will invoke collect() with a collector callback
76           that returns a reference to $content the first time and an empty
77           string the next.
78

SEE ALSO

80       Inspect the LWP/Protocol/file.pm and LWP/Protocol/http.pm files for
81       examples of usage.
82
84       Copyright 1995-2001 Gisle Aas.
85
86       This library is free software; you can redistribute it and/or modify it
87       under the same terms as Perl itself.
88
89
90
91perl v5.16.3                      2012-01-14                  LWP::Protocol(3)
Impressum