{
    "mode": "perldoc",
    "parameter": "LWP::Protocol",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/LWP%3A%3AProtocol/json",
    "generated": "2026-06-13T21:47:38Z",
    "synopsis": "package LWP::Protocol::foo;\nuse parent qw(LWP::Protocol);",
    "sections": {
        "NAME": {
            "content": "LWP::Protocol - Base class for LWP protocols\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package LWP::Protocol::foo;\nuse parent qw(LWP::Protocol);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This class is used as the base class for all protocol implementations supported by the LWP\nlibrary.\n\nWhen creating an instance of this class using \"LWP::Protocol::create($url)\", and you get an\ninitialized subclass appropriate for that access method. In other words, the \"create\" in\nLWP::Protocol function calls the constructor for one of its subclasses.\n\nAll derived \"LWP::Protocol\" classes need to override the \"request()\" method which is used to\nservice a request. The overridden method can make use of the \"collect()\" method to collect\ntogether chunks of data as it is received.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "The following methods and functions are provided:\n\nnew\nmy $prot = LWP::Protocol->new();\n\nThe LWP::Protocol constructor is inherited by subclasses. As this is a virtual base class this\nmethod should not be called directly.\n\ncreate\nmy $prot = LWP::Protocol::create($scheme)\n\nCreate an object of the class implementing the protocol to handle the given scheme. This is a\nfunction, not a method. It is more an object factory than a constructor. This is the function\nuser agents should use to access protocols.\n\nimplementor\nmy $class = LWP::Protocol::implementor($scheme, [$class])\n\nGet and/or set implementor class for a scheme. Returns '' if the specified scheme is not\nsupported.\n\nrequest\n$response = $protocol->request($request, $proxy, undef);\n$response = $protocol->request($request, $proxy, '/tmp/sss');\n$response = $protocol->request($request, $proxy, \\&callback, 1024);\n\nDispatches a request over the protocol, and returns a response object. This method needs to be\noverridden in subclasses. Refer to LWP::UserAgent for description of the arguments.\n\ncollect\nmy $res = $prot->collect(undef, $response, $collector); # stored in $response\nmy $res = $prot->collect($filename, $response, $collector);\nmy $res = $prot->collect(sub { ... }, $response, $collector);\n\nCollect the content of a request, and process it appropriately into a scalar, file, or by\ncalling a callback. If the first parameter is undefined, then the content is stored within the\n$response. If it's a simple scalar, then it's interpreted as a file name and the content is\nwritten to this file. If it's a code reference, then content is passed to this routine.\n\nThe collector is a routine that will be called and which is responsible for returning pieces (as\nref to scalar) of the content to process. The $collector signals \"EOF\" by returning a reference\nto an empty string.\n\nThe return value is the HTTP::Response object reference.\n\nNote: We will only use the callback or file argument if \"$response->issuccess()\". This avoids\nsending content data for redirects and authentication responses to the callback which would be\nconfusing.\n\ncollectonce\n$prot->collectonce($arg, $response, $content)\n\nCan be called when the whole response content is available as content. This will invoke\n\"collect\" in LWP::Protocol with a collector callback that returns a reference to $content the\nfirst time and an empty string the next.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Inspect the LWP/Protocol/file.pm and LWP/Protocol/http.pm files for examples of usage.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 1995-2001 Gisle Aas.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "LWP::Protocol - Base class for LWP protocols",
    "flags": [],
    "examples": [],
    "see_also": []
}