{"id":482,"date":"2010-06-27T22:53:34","date_gmt":"2010-06-27T21:53:34","guid":{"rendered":"http:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/"},"modified":"2010-06-27T22:53:34","modified_gmt":"2010-06-27T21:53:34","slug":"lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore","status":"publish","type":"post","link":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/","title":{"rendered":"LWP::Simple for Perl 6, now with (partial) BasicAuth support and getstore()"},"content":{"rendered":"<p>I just pushed out another update for the <a href=\"http:\/\/github.com\/cosimo\/perl6-lwp-simple\" rel=\"nofollow\">LWP::Simple<\/a> module for Perl 6. This time, the main work was:<\/p>\n<ul>\n<li>refactoring the code and adding unit tests for the URL parsing (that might even grow into a Perl 6 URI module<\/li>\n<li>adding partial basic auth support. To be complete and working, it needs to base64 encode the user\/password pair. Not implemented yet. I&#39;ll see if I get around to it, or if someone has done it already.<\/li>\n<li>adding a <code>getstore()<\/code> method, that writes on to disk the downloaded content. Unfortunately that needs to <b>strip the HTTP headers and <code>undestand chunked transfers<\/code> for it to be remotely useful.<\/b><\/li>\n<\/ul>\n<p>It was nice to see the module grow in both functionality, code and unit tests coverage. I had to workaround a couple of problems I couldn&#39;t understand. I was extremely lazy and I didn&#39;t even look up <a href=\"http:\/\/perlcabal.org\/syn\/\" rel=\"nofollow\">Synopses<\/a>, so I assume it&#39;s my fault. However.<\/p>\n<p>The first is the use of <code>.match()<\/code> and <code>~~<\/code> to match against a regular expression. I found that the following code:<\/p>\n<pre>\r\nmy $hostname = &#39;cosimo:eelst@faveclub.eelst.com&#39;;\r\nif $hostname.match(&#39;^cosimo&#39;) {\r\n    # Doesn&#39;t enter here\r\n}\r\n<\/pre>\n<p>doesn&#39;t trigger a match. However, this other here:<\/p>\n<pre>\r\nmy $hostname = &#39;cosimo:eelst@faveclub.eelst.com&#39;;\r\nif $hostname ~~ \/^cosimo\/ {\r\n    # Does match\r\n}\r\n<\/pre>\n<p>And, in the same way, something similarly surprising. The following code <b>correctly matches<\/b>:<\/p>\n<pre>\r\nmy $hostname = &#39;cosimo:eelst@faveclub.eelst.com&#39;;\r\nif $hostname ~~ \/^ .+ : .+ @ .+ $\/ {\r\n    say &#39;(user:pass@host) matches&#39;;\r\n} else {\r\n    say &#39;(user:pass@host) does not match&#39;;\r\n}\r\n<\/pre>\n<p>but <b>adding captures<\/b> makes the same exact regex fail:<\/p>\n<pre>\r\nmy $hostname = &#39;cosimo:eelst@faveclub.eelst.com&#39;;\r\nif $hostname ~~ \/^ (.+) : (.+)  @ (.+) $\/ {\r\n    say &#39;(with captures) matches&#39;;\r\n} else {\r\n    say &#39;(with captures) does not match&#39;;\r\n}\r\n<\/pre>\n<p>There are also very nice things about programming in Perl 6 that are slowly sucking me in this fantastic language. This is part of a test script for LWP::Simple:<\/p>\n<pre>\r\n#\r\n# Test the parse_url() method\r\n#\r\nuse v6;\r\nuse Test;\r\nuse LWP:: Simple;\r\n\r\nmy @test = (\r\n    { User-Agent =&gt; &#39;Opera\/9.80 (WinNT; 6.0) Version\/10.60&#39; },\r\n    &quot;User-Agent: Opera\/9.80 (WinNT; 6.0) Version\/10.60rn&quot;,\r\n\r\n    { Connection =&gt; &#39;close&#39; },\r\n    &quot;Connection: closern&quot;,\r\n);\r\n\r\nfor @test -&gt; %headers, $expected_str {\r\n    my $hdr_str = LWP:: Simple.stringify_headers(%headers);\r\n    is($hdr_str, $expected_str, &#39;OK - &#39; ~ $hdr_str);\r\n}\r\n<\/pre>\n<p>Note how in the <code>for<\/code> statement we can &quot;extract&quot; the hash and string from the <code>@test<\/code> array with:<\/p>\n<pre>\r\nfor @test -&gt; %headers, $expected_string {\r\n    # Loop body\r\n}\r\n<\/pre>\n<p>It&#39;s not a big deal, other languages have it, but Perl 6 is filled with this small niceties that make the resulting code still feel like Perl, but also, don&#39;t know exactly, more robust perhaps?<\/p>\n<p>So, to conclude:<\/p>\n<ul>\n<li>Anyone with a Perl 6 implementation of <a href=\"http:\/\/search.cpan.org\/dist\/MIME-Base64\" rel=\"nofollow\">MIME::Base64<\/a> ? Speak up before I create a monster :)<\/li>\n<li>Anyone cares enough to take on the chunked transfer encoding support?<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I just pushed out another update for the LWP::Simple module for Perl 6. This time, the main work was: refactoring the code and adding unit tests for the URL parsing (that might even grow into a Perl 6 URI module adding partial basic auth support. To be complete and working, it needs to base64 encode [&hellip;]<\/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":[91,287,50,290,286],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>LWP::Simple for Perl 6, now with (partial) BasicAuth support and getstore() - Random hacking<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LWP::Simple for Perl 6, now with (partial) BasicAuth support and getstore() - Random hacking\" \/>\n<meta property=\"og:description\" content=\"I just pushed out another update for the LWP::Simple module for Perl 6. This time, the main work was: refactoring the code and adding unit tests for the URL parsing (that might even grow into a Perl 6 URI module adding partial basic auth support. To be complete and working, it needs to base64 encode [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/\" \/>\n<meta property=\"og:site_name\" content=\"Random hacking\" \/>\n<meta property=\"article:published_time\" content=\"2010-06-27T21:53:34+00:00\" \/>\n<meta name=\"author\" content=\"cosimo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cosimo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/\"},\"author\":{\"name\":\"cosimo\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"headline\":\"LWP::Simple for Perl 6, now with (partial) BasicAuth support and getstore()\",\"datePublished\":\"2010-06-27T21:53:34+00:00\",\"dateModified\":\"2010-06-27T21:53:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/\"},\"wordCount\":324,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"keywords\":[\"development\",\"LWP::Simple\",\"perl\",\"perl6\",\"rakudo\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/\",\"name\":\"LWP::Simple for Perl 6, now with (partial) BasicAuth support and getstore() - Random hacking\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\"},\"datePublished\":\"2010-06-27T21:53:34+00:00\",\"dateModified\":\"2010-06-27T21:53:34+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LWP::Simple for Perl 6, now with (partial) BasicAuth support and getstore()\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\",\"name\":\"Random hacking\",\"description\":\"Assume nothing. Code defensively. Keep it simple, stupid!\",\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\",\"name\":\"cosimo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"caption\":\"cosimo\"},\"logo\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LWP::Simple for Perl 6, now with (partial) BasicAuth support and getstore() - Random hacking","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/","og_locale":"en_US","og_type":"article","og_title":"LWP::Simple for Perl 6, now with (partial) BasicAuth support and getstore() - Random hacking","og_description":"I just pushed out another update for the LWP::Simple module for Perl 6. This time, the main work was: refactoring the code and adding unit tests for the URL parsing (that might even grow into a Perl 6 URI module adding partial basic auth support. To be complete and working, it needs to base64 encode [&hellip;]","og_url":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/","og_site_name":"Random hacking","article_published_time":"2010-06-27T21:53:34+00:00","author":"cosimo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"cosimo","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/#article","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/"},"author":{"name":"cosimo","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"headline":"LWP::Simple for Perl 6, now with (partial) BasicAuth support and getstore()","datePublished":"2010-06-27T21:53:34+00:00","dateModified":"2010-06-27T21:53:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/"},"wordCount":324,"commentCount":0,"publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"keywords":["development","LWP::Simple","perl","perl6","rakudo"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/","url":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/","name":"LWP::Simple for Perl 6, now with (partial) BasicAuth support and getstore() - Random hacking","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website"},"datePublished":"2010-06-27T21:53:34+00:00","dateModified":"2010-06-27T21:53:34+00:00","breadcrumb":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/lwpsimple-for-perl-6-now-with-partial-basicauth-support-and-getstore\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.streppone.it\/cosimo\/blog\/"},{"@type":"ListItem","position":2,"name":"LWP::Simple for Perl 6, now with (partial) BasicAuth support and getstore()"}]},{"@type":"WebSite","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website","url":"https:\/\/www.streppone.it\/cosimo\/blog\/","name":"Random hacking","description":"Assume nothing. Code defensively. Keep it simple, stupid!","publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1","name":"cosimo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","caption":"cosimo"},"logo":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/482"}],"collection":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/comments?post=482"}],"version-history":[{"count":0,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/482\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/media?parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/categories?post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/tags?post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}