{"id":6639,"date":"2022-12-20T19:19:30","date_gmt":"2022-12-20T22:19:30","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/lwpprotocol-man3\/"},"modified":"2022-12-20T19:19:30","modified_gmt":"2022-12-20T22:19:30","slug":"lwpprotocol-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/lwpprotocol-man3\/","title":{"rendered":"LWP::Protocol (man3)"},"content":{"rendered":"<h1 align=\"center\">LWP::Protocol<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#METHODS\">METHODS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">LWP::Protocol \u2212 Base class for LWP protocols<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">package LWP::Protocol::foo; <br \/> use base qw(LWP::Protocol);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This class is used as the base class for all protocol implementations supported by the <small>LWP<\/small> library.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">When creating an instance of this class using &#8220;LWP::Protocol::create($url)&#8221;, and you get an initialized subclass appropriate for that access method. In other words, the &#8220;create&#8221; in LWP::Protocol function calls the constructor for one of its subclasses.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">All derived &#8220;LWP::Protocol&#8221; classes need to override the <b>request()<\/b> method which is used to service a request. The overridden method can make use of the <b>collect()<\/b> function to collect together chunks of data as it is received.<\/p>\n<h2>METHODS <a name=\"METHODS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The following methods and functions are provided:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>new<\/b> <br \/> my $prot = LWP::Protocol\u2212>new();<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The LWP::Protocol constructor is inherited by subclasses. As this is a virtual base class this method should <b>not<\/b> be called directly.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>create<\/b> <br \/> my $prot = LWP::Protocol::create($scheme)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Create an object of the class implementing the protocol to handle the given scheme. This is a function, not a method. It is more an object factory than a constructor. This is the function user agents should use to access protocols.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>implementor<\/b> <br \/> my $class = LWP::Protocol::implementor($scheme, [$class])<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Get and\/or set implementor class for a scheme. Returns &#8221; if the specified scheme is not supported.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>request<\/b> <br \/> $response = $protocol\u2212>request($request, $proxy, undef); <br \/> $response = $protocol\u2212>request($request, $proxy, &#8216;\/tmp\/sss&#8217;); <br \/> $response = $protocol\u2212>request($request, $proxy, &#038;callback, 1024);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Dispatches a request over the protocol, and returns a response object. This method needs to be overridden in subclasses. Refer to LWP::UserAgent for description of the arguments.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>collect<\/b> <br \/> my $res = $prot\u2212>collect(undef, $response, $collector); # stored in $response <br \/> my $res = $prot\u2212>collect($filename, $response, $collector); <br \/> my $res = $prot\u2212>collect(sub { &#8230; }, $response, $collector);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Collect the content of a request, and process it appropriately into a scalar, file, or by calling a callback. If the first parameter is undefined, then the content is stored within the $response. If it\u2019s a simple scalar, then it\u2019s interpreted as a file name and the content is written to this file. If it\u2019s a code reference, then content is passed to this routine.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The collector is a routine that will be called and which is responsible for returning pieces (as ref to scalar) of the content to process. The $collector signals &#8220;EOF&#8221; by returning a reference to an empty string.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The return value is the HTTP::Response object reference.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Note:<\/b> We will only use the callback or file argument if &#8220;$response\u2212>is_success()&#8221;. This avoids sending content data for redirects and authentication responses to the callback which would be confusing.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>collect_once<\/b> <br \/> $prot\u2212>collect_once($arg, $response, $content)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Can be called when the whole response content is available as content. This will invoke &#8220;collect&#8221; in LWP::Protocol with a collector callback that returns a reference to $content the first time and an empty string the next.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Inspect the <i>LWP\/Protocol\/file.pm<\/i> and <i>LWP\/Protocol\/http.pm<\/i> files for examples of usage.<\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Copyright 1995\u22122001 Gisle Aas.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This library is free software; you can redistribute it and\/or modify it under the same terms as Perl itself.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  LWP::Protocol \u2212 Base class for LWP protocols <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3020,3007],"class_list":["post-6639","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-lwpprotocol","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6639","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6639"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6639\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}